Button click action : Button « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » ButtonScreenshots 
Button click action
Button click action

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace AddControls
{
  /// <summary>
  /// Summary description for FormAddControls.
  /// </summary>
  public class FormAddControls : System.Windows.Forms.Form
  {
    private System.Windows.Forms.ListBox listBox1;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.Button button2;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public FormAddControls()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.textBox1 = new System.Windows.Forms.TextBox();
      this.button1 = new System.Windows.Forms.Button();
      this.button2 = new System.Windows.Forms.Button();
      this.listBox1 = new System.Windows.Forms.ListBox();
      this.SuspendLayout();
      // 
      // textBox1
      // 
      this.textBox1.Location = new System.Drawing.Point(38200);
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new System.Drawing.Size(21620);
      this.textBox1.TabIndex = 1;
      this.textBox1.Text = "";
      // 
      // button1
      // 
      this.button1.Location = new System.Drawing.Point(48240);
      this.button1.Name = "button1";
      this.button1.Size = new System.Drawing.Size(8024);
      this.button1.TabIndex = 2;
      this.button1.Text = "Add Item";
      this.button1.Click += new System.EventHandler(this.button1_Click);
      this.button1.MouseEnter += new System.EventHandler(this.Buttons_OnMouseEnter);
      this.button1.MouseLeave += new System.EventHandler(this.Buttons_OnMouseLeave);
      // 
      // button2
      // 
      this.button2.Location = new System.Drawing.Point(160240);
      this.button2.Name = "button2";
      this.button2.Size = new System.Drawing.Size(9624);
      this.button2.TabIndex = 3;
      this.button2.Text = "Cancel";
      this.button2.Click += new System.EventHandler(this.button2_Click);
      this.button2.MouseEnter += new System.EventHandler(this.Buttons_OnMouseEnter);
      this.button2.MouseLeave += new System.EventHandler(this.Buttons_OnMouseLeave);
      // 
      // listBox1
      // 
      this.listBox1.Location = new System.Drawing.Point(3832);
      this.listBox1.Name = "listBox1";
      this.listBox1.Size = new System.Drawing.Size(216147);
      this.listBox1.TabIndex = 0;
      // 
      // FormAddControls
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(292273);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.button2,
                                      this.button1,
                                      this.textBox1,
                                      this.listBox1});
      this.Name = "FormAddControls";
      this.Text = "FormAddControls";
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new FormAddControls());
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
      if (textBox1.Text == "")
        return;
      string strAdd = textBox1.Text;
      if (listBox1.FindString (strAdd, -10)
      {
        listBox1.Items.Add (strAdd);
        textBox1.Text = "";
        textBox1.Focus ();
        return;
      }
      MessageBox.Show ("\"" + strAdd + "\" is already in the list box""Duplicate");
    }

    private void button2_Click(object sender, System.EventArgs e)
    {
      Application.Exit();
    }

    private void Buttons_OnMouseEnter(object sender, System.EventArgs e)
    {
      Button btn = (Buttonsender;
      btn.BackColor = Color.LightGray;
    }

    private void Buttons_OnMouseLeave(object sender, System.EventArgs e)
    {
      Button btn = (Buttonsender;
      btn.BackColor = SystemColors.Control;
    }
  }
}



           
       
Related examples in the same category
1.Button Image, Size, Parent
2.Button Name, TabIndex, Text
3.Button Localtion
4.Button FlatStyle Styles
5.Add image to ButtonAdd image to Button
6.Add quotation char to Button textAdd quotation char to Button text
7.Change Standard Button Text AlignmentChange Standard Button Text Alignment
8.Popup button, Flat button and Image buttonPopup button, Flat button and Image button
9.Change Button textChange Button text
10.Add two action listeners to a buttonAdd two action listeners to a button
11.Add a ButtonAdd a Button
12.Handle button messagesHandle button messages
13.Add button to formAdd button to form
14.Picture ButtonPicture Button
15.Button Action DemoButton Action Demo
16.Hot Track Button HostHot Track Button Host
17.Button GeneratorButton Generator
18.Popup TextPopup Text
19.Paint Owner-Draw 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.