//about menu item
        private void _aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox aboutbox = new AboutBox();

            aboutbox.ShowDialog();
        }
Beispiel #2
0
        // Shared click Event handler for buttons and menu items
        private void _OrderFormButtonClickEventHandler(Object sender, EventArgs e)
        {
            // declaring a Button object
            Button            buttonClicked   = null;
            ToolStripMenuItem menuItemClicked = null;

            try
            {
                // casting the sender object into Button
                buttonClicked = sender as Button;

                // if it wasn't clicked by Button, buttonClicked will be null
                if (buttonClicked == null)
                {
                    throw new Exception(); // throw exception so as to cast the sender to menu item now
                }
            }
            catch (Exception ex)
            {
                // casting the sender object into a ToolStripMenuItem
                menuItemClicked = sender as ToolStripMenuItem;
            }

            // perform action based on tag identification
            switch ((buttonClicked != null) ? buttonClicked.Tag.ToString() : menuItemClicked.Tag.ToString())
            {
            case "cancel":
            case "exit":
                // exit the application

                // confirm the closure
                DialogResult result = MessageBox.Show("Are you sure you want to exit the application?", "Confirm Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    Application.Exit();
                }
                break;

            case "finish":
                // Display the message of order sucess
                MessageBox.Show("Thanks for placing your order with us!" + Environment.NewLine + "Your order will be processed in 7-10 business days.", "Order placed");
                // exit the application
                Application.Exit();
                break;

            case "back":
                // Show the previous ProductInfoForm
                productInfoForm.Show();

                // Close this form (no longer required)
                this.Close();
                break;

            case "about":
                // Create an instance of the About Box
                AboutBox aboutBox = new AboutBox();
                // Display the modal About Box
                aboutBox.ShowDialog();
                break;

            case "print":
                // message to inform users the order info being printed
                MessageBox.Show("Your order information for " + this.ManufacturerTextBox.Text + " " + this.ModelTextBox.Text + " is being printed.", "Print Confirmation");
                break;
            }
        }