About DialogBox : Dialog « GUI Windows Forms « C# / CSharp Tutorial






using System;
using System.Drawing;
using System.Windows.Forms;
   

class AboutDialogBox: Form
{
     public static void Main()
     {
          AboutDialogBox dlg = new AboutDialogBox();
          dlg.ShowDialog();
     }    
     public AboutDialogBox()
     {
          Text = "About AboutBox";
   
          StartPosition   = FormStartPosition.CenterParent;
          FormBorderStyle = FormBorderStyle.FixedDialog;
          ControlBox      = false;
          MaximizeBox     = false;
          MinimizeBox     = false;
          ShowInTaskbar   = false;
   
          Label label1     = new Label();
          label1.Parent    = this;
          label1.Text      = " AboutBox Version 1.0 ";
          label1.Font      = new Font(FontFamily.GenericSerif, 24, 
                                      FontStyle.Italic);
          label1.AutoSize  = true;
          label1.TextAlign = ContentAlignment.MiddleCenter;
   
          Icon icon = new Icon(GetType(), "AboutBox.ico");
   
          PictureBox picbox = new PictureBox();
          picbox.Parent     = this;
          picbox.Image      = icon.ToBitmap();
          picbox.SizeMode   = PictureBoxSizeMode.AutoSize;
          picbox.Location   = new Point(label1.Font.Height / 2, 
                                        label1.Font.Height / 2);
   
          label1.Location  = new Point(picbox.Right,label1.Font.Height / 2);
   
          int iClientWidth = label1.Right;
   
          Label label2     = new Label();
          label2.Parent    = this;
          label2.Text      = "\x00A9 ";
          label2.Font      = new Font(FontFamily.GenericSerif, 16);
          label2.Location  = new Point(0, label1.Bottom + 
                                          label2.Font.Height);
          label2.Size      = new Size(iClientWidth, label2.Font.Height);
          label2.TextAlign = ContentAlignment.MiddleCenter;
   
          Button button   = new Button();
          button.Parent   = this;
          button.Text     = "OK";
          button.Size     = new Size(4 * button.Font.Height, 
                                     2 * button.Font.Height);
          button.Location = new Point((iClientWidth - button.Size.Width) / 2,
                                   label2.Bottom + 2 * button.Font.Height);
   
          button.DialogResult = DialogResult.OK;
   
          CancelButton = button;
          AcceptButton = button;
   
          ClientSize = new Size(iClientWidth, 
                                button.Bottom + 2 * button.Font.Height);
     }
}








23.52.Dialog
23.52.1.Call ShowDialog on Form object
23.52.2.About DialogBox
23.52.3.Define your own dialog boxDefine your own dialog box
23.52.4.Dialog Apply Event IllustrationDialog Apply Event Illustration
23.52.5.Define Apply Button action method in dialog classDefine Apply Button action method in dialog class
23.52.6.Set DialogResult in your own dialog classSet DialogResult in your own dialog class
23.52.7.Create a custom dialog with radio button groupCreate a custom dialog with radio button group
23.52.8.Dialog with two buttonsDialog with two buttons