Use of DialogBox

Use of Dialog Box:
Dialog boxes are used to confirm an operation from the user.
Now look at an example which uses dialog box. The application will ask user whether to open another copy of the form or not. When user will click on the button ShowForm a dialog box will appear which will confirm opening of new form. If user clicks on Yes button new form will be opened otherwise not.
private void ShowForm_Click(object sender, EventArgs e)
        {
            DialogResult dlg;
            dlg = MessageBox.Show("Do you really want to open another copy of this form", "Confirmation", MessageBoxButtons.YesNo);
            if (dlg == DialogResult.Yes)
            {
                Form1 ch = new Form1();
                ch.Show();
                ch.BringToFront();
            }
Now when application will run and user will click ShowForm button a dialog box will appear
Now if user clicks Yes button a new form will be opened.if user clicks No nothing will happen

Comments

Popular posts from this blog

Using Progress Bar In C#

Get elements by class name in javascript

Jquery serer side datatables in asp.net