Dialog Apply Event Illustration : Dialog « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » Dialog 
23.52.4.Dialog Apply Event Illustration
Dialog Apply Event Illustration
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class DialogApplyEvent : System.Windows.Forms.Form
{
  private System.Windows.Forms.Button btnCreate;
  private System.Windows.Forms.Label lblReturn;

  public DialogApplyEvent()
  {
    InitializeComponent();
  }

  private void InitializeComponent()
  {
    this.btnCreate = new System.Windows.Forms.Button();
    this.lblReturn = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // btnCreate
    // 
    this.btnCreate.Location = new System.Drawing.Point(72176);
    this.btnCreate.Name = "btnCreate";
    this.btnCreate.Size = new System.Drawing.Size(14423);
    this.btnCreate.TabIndex = 0;
    this.btnCreate.Text = "Create Dialog Box";
    this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
    // 
    // lblReturn
    // 
    this.lblReturn.Location = new System.Drawing.Point(8888);
    this.lblReturn.Name = "lblReturn";
    this.lblReturn.TabIndex = 1;
    // 
    // DialogApplyEvent
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(513);
    this.ClientSize = new System.Drawing.Size(292273);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                             this.lblReturn,
                                             this.btnCreate});
    this.ResumeLayout(false);

  }
  [STAThread]
  static void Main() 
  {
    Application.Run(new DialogApplyEvent());
  }

  private void btnCreate_Click(object sender, System.EventArgs e)
  {
    DialogDemo dlg = new DialogDemo();
    dlg.EnableApplyButton = false;

    dlg.ClickApply += new EventHandler(DialogDemoOnApply);
    
    dlg.ShowDialog();
    
    if (dlg.DialogResult == DialogResult.OK)
      {lblReturn.Text = dlg.TextOut;}
    else
      {lblReturn.Text = dlg.DialogResult.ToString();}
  }
  
  private void DialogDemoOnApply(object sender, System.EventArgs e)
  {
    DialogDemo dlg = (DialogDemo)sender;
    lblReturn.Text = dlg.TextOut;
    dlg.EnableApplyButton = false;  
  }

}

class DialogDemo : Form
{
  private Button btnApply;
  private TextBox txt;
  public event EventHandler ClickApply;
  
  public DialogDemo()
  {
    FormBorderStyle = FormBorderStyle.FixedDialog;
    BackColor = System.Drawing.Color.Aquamarine;
    ControlBox = false;
    MaximizeBox = false;
    MinimizeBox = false;
    ShowInTaskbar = false;
    Size = new Size(400,200);
    StartPosition = FormStartPosition.CenterScreen;

    Button btnOK = new Button();
    btnOK.Text = "OK";
    btnOK.DialogResult = DialogResult.OK;
    btnOK.Location = new Point(50,50);
    btnOK.TabIndex = 0;
    btnOK.Click += new EventHandler(ApplyButtonOnClick);
    Controls.Add(btnOK);
    
    btnApply = new Button();
    btnApply.Text = "Apply";
    btnApply.Location = new Point(150,50);
    btnApply.TabIndex = 1;
    btnApply.Enabled = false;
    btnApply.Click += new EventHandler(ApplyButtonOnClick);
    Controls.Add(btnApply);
    
    Button btnCancel = new Button();
    btnCancel.Text = "Cancel";
    btnCancel.DialogResult = DialogResult.Cancel;
    btnCancel.Location = new Point(250,50);
    btnCancel.TabIndex = 2;
    Controls.Add(btnCancel);

    txt = new TextBox();
    txt.Size = new Size(100,15);
    txt.Location = new Point(150,15);
    txt.TextChanged += new EventHandler(TextBoxChanged);
    Controls.Add(txt);
    
  }
  
  private void TextBoxChanged(object sender, EventArgs e)
  {
    this.EnableApplyButton = true;  
  }

  public bool EnableApplyButton
  {
    get {return btnApply.Enabled; }
    set {btnApply.Enabled = value; }
  }
  
  public string TextOut
  {
    get {return txt.Text; }
  }
  
  private void ApplyButtonOnClick (object sender, System.EventArgs e)
  {
    if (ClickApply != null)
      ClickApply(this, new EventArgs());
  }
}
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.