Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

Call ShowDialog on Form object

using System; using System.Drawing; using System.Windows.Forms;     class SimplerDialog: Form {      public static void Main()      {           Application.Run(new SimplerDialog());      }      public SimplerDialog()      {           Text = "Simpler Dialog";               Menu = new MainMenu();           Menu.MenuItems.Add("&Dialog!", new EventHandler(MenuOnClick));      }      void MenuOnClick(object obj, EventArgs ea)      {           SimplerDialogBox dlg = new SimplerDialogBox();           DialogResult     dr  = dlg.ShowDialog();               Console.WriteLine(dr);      } } class SimplerDialogBox: Form {      public SimplerDialogBox()      {           Text = "Simpler Dialog Box";               FormBorderStyle = FormBorderStyle.FixedDialog;           ControlBox      = false;           MaximizeBox     = false;           MinimizeBox     = false;           ShowInTaskbar   = false;               Button btn = new Button();           btn.Parent   = this;           btn.Text     = "OK";           btn.Location = new Point(50, 50);           btn.Size     = new Size (10 * Font.Height, 2 * Font.Height);           btn.DialogResult = DialogResult.OK;               btn = new Button();           btn.Parent   = this;           btn.Text     = "Cancel";           btn.Location = new Point(50, 100);           btn.Size     = new Size (10 * Font.Height, 2 * Font.Height);           btn.DialogResult = DialogResult.Cancel;      } }