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?
Printable View
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?
If it is dialog based form use ShowDialog() member. If it should be "normal" window use Show() member:
martinCode:protected void OnSomeEvent(object sender, EventArgs args)
{
FormClass frm = new FormClass();
frm.Show(); // Normal window
// frm.ShowDialog(); // Dialog (modal window)
}
10x a lot.
Can you explain how do I do a modal window (dialog)
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.
MartinCode:// ....
DialogResult dlgResult = YourNewForm.ShowDialog();
if (dlgResult == DialogResult.OK)
MessageBox.Show("You close your dialog by pressing OK button");
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