home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Dialog Boxes / BetterDialog / BetterDialog.cs next >
Encoding:
Text File  |  2001-01-15  |  2.3 KB  |  78 lines

  1. //-------------------------------------------
  2. // BetterDialog.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class BetterDialog: Form
  9. {
  10.      string strDisplay = "";
  11.  
  12.      public static void Main()
  13.      {
  14.           Application.Run(new BetterDialog());
  15.      }
  16.      public BetterDialog()
  17.      {
  18.           Text = "Better Dialog";
  19.  
  20.           Menu = new MainMenu();
  21.           Menu.MenuItems.Add("&Dialog!", new EventHandler(MenuOnClick));
  22.      }
  23.      void MenuOnClick(object obj, EventArgs ea)
  24.      {
  25.           BetterDialogBox dlg = new BetterDialogBox();
  26.           DialogResult    dr  = dlg.ShowDialog();
  27.  
  28.           strDisplay = "Dialog box terminated with " + dr + "!";
  29.           Invalidate();
  30.      }
  31.      protected override void OnPaint(PaintEventArgs pea)
  32.      {
  33.           Graphics grfx = pea.Graphics;
  34.           grfx.DrawString(strDisplay, Font, new SolidBrush(ForeColor), 0, 0);
  35.      }
  36. }
  37. class BetterDialogBox: Form
  38. {
  39.      public BetterDialogBox()
  40.      {
  41.           Text = "Better Dialog Box";
  42.  
  43.                // Standard stuff for dialog boxes
  44.  
  45.           FormBorderStyle = FormBorderStyle.FixedDialog;
  46.           ControlBox      = false;
  47.           MaximizeBox     = false;
  48.           MinimizeBox     = false;
  49.           ShowInTaskbar   = false;
  50.           StartPosition   = FormStartPosition.Manual;
  51.           Location        = ActiveForm.Location + 
  52.                             SystemInformation.CaptionButtonSize +
  53.                             SystemInformation.FrameBorderSize;
  54.  
  55.                // Create OK button.
  56.  
  57.           Button btn = new Button();
  58.           btn.Parent   = this;
  59.           btn.Text     = "OK";
  60.           btn.Location = new Point(50, 50);
  61.           btn.Size     = new Size (10 * Font.Height, 2 * Font.Height);
  62.           btn.DialogResult = DialogResult.OK;
  63.  
  64.           AcceptButton = btn;
  65.  
  66.                // Create Cancel button.
  67.  
  68.           btn = new Button();
  69.           btn.Parent   = this;
  70.           btn.Text     = "Cancel";
  71.           btn.Location = new Point(50, 100);
  72.           btn.Size     = new Size (10 * Font.Height, 2 * Font.Height);
  73.           btn.DialogResult = DialogResult.Cancel;
  74.  
  75.           CancelButton = btn;
  76.      }
  77. }
  78.