Button Generator : Button « GUI Windows Form « C# / C Sharp

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. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » GUI Windows Form » ButtonScreenshots 
Button Generator
Button Generator

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ButtonGenerator
{
    /// <summary>
    /// Summary description for ButtonGenerator.
    /// </summary>
    public class ButtonGenerator : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.GroupBox GroupBox2;
        internal System.Windows.Forms.GroupBox GroupBox1;
        internal System.Windows.Forms.Label Label1;
        internal System.Windows.Forms.TextBox txtLeft;
        internal System.Windows.Forms.Label Label2;
        internal System.Windows.Forms.Button cmdCreate;
        internal System.Windows.Forms.TextBox txtTop;
        internal System.Windows.Forms.StatusBar status;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public ButtonGenerator()
        {
            //
            // 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.GroupBox2 = new System.Windows.Forms.GroupBox();
            this.GroupBox1 = new System.Windows.Forms.GroupBox();
            this.Label1 = new System.Windows.Forms.Label();
            this.txtLeft = new System.Windows.Forms.TextBox();
            this.Label2 = new System.Windows.Forms.Label();
            this.cmdCreate = new System.Windows.Forms.Button();
            this.txtTop = new System.Windows.Forms.TextBox();
            this.status = new System.Windows.Forms.StatusBar();
            this.GroupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // GroupBox2
            // 
            this.GroupBox2.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left
                | System.Windows.Forms.AnchorStyles.Right);
            this.GroupBox2.Location = new System.Drawing.Point(0180);
            this.GroupBox2.Name = "GroupBox2";
            this.GroupBox2.Size = new System.Drawing.Size(3684);
            this.GroupBox2.TabIndex = 10;
            this.GroupBox2.TabStop = false;
            // 
            // GroupBox1
            // 
            this.GroupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                    this.Label1,
                                                                                    this.txtLeft,
                                                                                    this.Label2,
                                                                                    this.cmdCreate,
                                                                                    this.txtTop});
            this.GroupBox1.Location = new System.Drawing.Point(126);
            this.GroupBox1.Name = "GroupBox1";
            this.GroupBox1.Size = new System.Drawing.Size(168128);
            this.GroupBox1.TabIndex = 9;
            this.GroupBox1.TabStop = false;
            // 
            // Label1
            // 
            this.Label1.Location = new System.Drawing.Point(1652);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(5216);
            this.Label1.TabIndex = 0;
            this.Label1.Text = "Left:";
            // 
            // txtLeft
            // 
            this.txtLeft.Location = new System.Drawing.Point(7652);
            this.txtLeft.Name = "txtLeft";
            this.txtLeft.Size = new System.Drawing.Size(6821);
            this.txtLeft.TabIndex = 4;
            this.txtLeft.Text = "200";
            // 
            // Label2
            // 
            this.Label2.Location = new System.Drawing.Point(1624);
            this.Label2.Name = "Label2";
            this.Label2.Size = new System.Drawing.Size(5216);
            this.Label2.TabIndex = 1;
            this.Label2.Text = "Top:";
            // 
            // cmdCreate
            // 
            this.cmdCreate.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.cmdCreate.Location = new System.Drawing.Point(3684);
            this.cmdCreate.Name = "cmdCreate";
            this.cmdCreate.Size = new System.Drawing.Size(11228);
            this.cmdCreate.TabIndex = 2;
            this.cmdCreate.Text = "Create Button";
            this.cmdCreate.Click += new System.EventHandler(this.cmdCreate_Click);
            // 
            // txtTop
            // 
            this.txtTop.Location = new System.Drawing.Point(7624);
            this.txtTop.Name = "txtTop";
            this.txtTop.Size = new System.Drawing.Size(6821);
            this.txtTop.TabIndex = 3;
            this.txtTop.Text = "50";
            // 
            // status
            // 
            this.status.Location = new System.Drawing.Point(0184);
            this.status.Name = "status";
            this.status.Size = new System.Drawing.Size(37222);
            this.status.TabIndex = 8;
            // 
            // ButtonGenerator
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(514);
            this.ClientSize = new System.Drawing.Size(372206);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.GroupBox2,
                                                                          this.GroupBox1,
                                                                          this.status});
            this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "ButtonGenerator";
            this.Text = "Button Generator";
            this.GroupBox1.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion

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

        private int buttonCount = 0;

        private void cmdCreate_Click(object sender, System.EventArgs e)
        {
            buttonCount++;

            // Create the button.
            Button newButton = new Button();
            newButton.Text = "Button " + buttonCount.ToString();
            newButton.Left = int.Parse(txtLeft.Text);
            newButton.Top = int.Parse(txtTop.Text);

            // Attach the event handler.
            newButton.Click += new EventHandler(ButtonHandler);

            this.Controls.Add(newButton);

        }


        private void ButtonHandler(object sender, System.EventArgs e)
        {
            status.Text = " You clicked ... ";
            status.Text += ((Button)sender).Text;
        }

    }
}



           
       
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. Button click actionButton click action
15. Picture ButtonPicture Button
16. Button Action DemoButton Action Demo
17. Hot Track Button HostHot Track Button Host
18. Popup TextPopup Text
19. Paint Owner-Draw Buttons
w___ww___.j_ava__2_s___.__c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.