Click to See Complete Forum and Search --> : Form question


RY33
March 12th, 2003, 01:58 AM
If I have the major form, and I created another one, which I need to be pop up when a menu item is pressed, how can I do it?

MartinL
March 12th, 2003, 04:04 AM
If it is dialog based form use ShowDialog() member. If it should be "normal" window use Show() member:


protected void OnSomeEvent(object sender, EventArgs args)
{
FormClass frm = new FormClass();

frm.Show(); // Normal window

// frm.ShowDialog(); // Dialog (modal window)
}


martin

RY33
March 12th, 2003, 04:50 AM
10x a lot.
Can you explain how do I do a modal window (dialog)

MartinL
March 12th, 2003, 05:19 AM
Just create normal form and put there some controls.
You should add there also button which will close that form. Lets say you want to add there button OK and button Cancel.

Add both those buttons there and set property DialogResult of those buttons to required value (OK and Cancel).

Then just show that dialog using ShowDialog() funtion. The function returns with the DialogResult of the button used to close the dialog.


// ....
DialogResult dlgResult = YourNewForm.ShowDialog();
if (dlgResult == DialogResult.OK)
MessageBox.Show("You close your dialog by pressing OK button");


Martin

pareshgh
March 12th, 2003, 02:01 PM
RYE,
ShowDialog is Modal dialog.
if you are looking for MDI application then

you can have a quick look at microsoft MDI application

which is attached here