Use DialogResult property in Form : Dialog « GUI Windows Form « C# / C Sharp






Use DialogResult property in Form

  


using System;
using System.Drawing;
using System.Windows.Forms;
   
class BetterDialog: Form
{
     public static void Main()
     {
          Application.Run(new BetterDialog());
     }
     public BetterDialog()
     {
          Menu = new MainMenu();
          Menu.MenuItems.Add("&Dialog!", new EventHandler(MenuOnClick));
     }
     void MenuOnClick(object obj, EventArgs ea)
     {
          BetterDialogBox dlg = new BetterDialogBox();
          DialogResult    dr  = dlg.ShowDialog();
   
          Console.WriteLine(dr);
     }
}
class BetterDialogBox: Form
{
     public BetterDialogBox()
     {
          Text = "Better Dialog Box";
   
          FormBorderStyle = FormBorderStyle.FixedDialog;
          ControlBox      = false;
          MaximizeBox     = false;
          MinimizeBox     = false;
          ShowInTaskbar   = false;
          StartPosition   = FormStartPosition.Manual;
          Location        = ActiveForm.Location + 
                            SystemInformation.CaptionButtonSize +
                            SystemInformation.FrameBorderSize;
   
          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;
   
          AcceptButton = btn;
   
          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;
   
          CancelButton = btn;
     }
}

   
  








Related examples in the same category

1.A dialog by user defined property
2.Color Fill dialog
3.Color Scroll Dialog Box
4.Italic User Message Dialog: your own dialog
5.Define your own dialog box and get user inputDefine your own dialog box and get user input
6.Microsoft.Win32.OpenFileDialog/SaveFileDialog
7.Get a list of files from a folder based on the result of a FolderBrowserDialog