WindowsForms: modal dialog in C#

http://www.eggheadcafe.com/community/aspnet/2/10007523/creating-a-modal-windows-form.aspx

Create Modal Popup Dialog in C#

Rawa’a Al-Jabaly replied to Shallu Gupta on 19-Mar-09 06:36 AM

Any form has the (AcceptButton and Cancel Button Properties) so create your form with two buttons, one is ok and the other is cancel. set AcceptButton = ok and CancelButton = cancel. After creating an instance from this form, use ShowDialog() method instead of Show(). The following example will explain to you what I mean:

Form1 frm = new Form1();

//Form1 has two buttons, button1 name is btnOk and button2 name is btnCancel

frm.AcceptButton = btnOk; //if you do this, then no need to write the OK handler.

frm.CancelButton = btnCancel; //if you do this, then no need to write the cancel handler.

frm.ShowDialog(); //creates a modal dialog.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s