Dialog with two buttons : Dialog « GUI Windows Forms « C# / CSharp Tutorial






Dialog with two buttons
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

public class SimpleDialog : Form
{
  public SimpleDialog()
  {
    Button OkButton=new Button();
    OkButton.Text = "Ok";
    OkButton.DialogResult = DialogResult.OK;
    OkButton.Location = new Point(8,20);
    OkButton.Size = new Size(50,24);
    this.Controls.Add(OkButton);

    Button CancelButton=new Button();
    CancelButton.Text = "Cancel";
    CancelButton.DialogResult = DialogResult.Cancel;
    CancelButton.Location = new Point(64,20);
    CancelButton.Size = new Size(50,24);
    this.Controls.Add(CancelButton);

    this.Text="Dialog";
    this.Size = new Size(130,90);
    this.FormBorderStyle = FormBorderStyle.FixedDialog;
    this.StartPosition = FormStartPosition.CenterParent;
    this.ControlBox = false;
  }
}


public class SimpleDialogTest
{
  public static void Main(){
    SimpleDialog dlg = new SimpleDialog();

    if(dlg.ShowDialog() == DialogResult.OK)
      MessageBox.Show("You clicked Ok");
    else
      MessageBox.Show("You clicked Cancel");

  }

}








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