Use Form.DialogResult : Form Properties « GUI Windows Forms « C# / CSharp Tutorial






using System;
using System.Drawing;
using System.Windows.Forms;
   
class SimpleDialog: Form
{
     public static void Main()
     {
          Application.Run(new SimpleDialog());
     }
     public SimpleDialog()
     {
   
          Menu = new MainMenu();
          Menu.MenuItems.Add("&Dialog!", new EventHandler(MenuOnClick));
     }
     void MenuOnClick(object obj, EventArgs ea)
     {
          SimpleDialogBox dlg = new SimpleDialogBox();
   
          dlg.ShowDialog();
   
          Console.WriteLine(dlg.DialogResult);
          
     }
}
class SimpleDialogBox: Form
{
     public SimpleDialogBox()
     {
          Text = "Simple 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.Click   += new EventHandler(ButtonOkOnClick);
   
          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.Click   += new EventHandler(ButtonCancelOnClick);
     }
     void ButtonOkOnClick(object obj, EventArgs ea)
     {
          DialogResult = DialogResult.OK;
     }
     void ButtonCancelOnClick(object obj, EventArgs ea)
     {
          DialogResult = DialogResult.Cancel;
     }
}








23.5.Form Properties
23.5.1.Change Form ClientSizeChange Form ClientSize
23.5.2.Form.StartPosition
23.5.3.Form with Maximize BoxForm with Maximize Box
23.5.4.Form without MinimizeBox and MaximizedBoxForm without MinimizeBox and MaximizedBox
23.5.5.Set form background colorSet form background color
23.5.6.Set form captionSet form caption
23.5.7.Set Form sizeSet Form size
23.5.8.Set Form Height
23.5.9.Set Form Width
23.5.10.Set FormBorderStyle
23.5.11.Center Form to the screenCenter Form to the screen
23.5.12.Resize redraw form: get/set Form styleResize redraw form: get/set Form style
23.5.13.Form Bounds SettingForm Bounds Setting
23.5.14.Form Opacity setting
23.5.15.Use Form.DialogResult