WinForm Basics


This program is for beginners who want tolearn the basics of C# WinForms. The following code gives a quick andeasy example of how WinForms work.

//Compilation

//CSC /r:system.drawing.dll /r:system.windows.forms.dll filename.cs
//For [ Beta 2]

using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
Label label1 = new Label();
TextBox textBox1 = new TextBox();
Button button1 = new Button();
Label label2 = new Label();

public Form1()
{
label1.Location = new Point(56, 48);
label1.Name = "label1";
label1.TabIndex = 0;
label1.Text = "Enter Ur Name : ";

textBox1.Location = new Point(176, 48);
textBox1.Name = "textBox1";
//textBox1.Size = new Size(112, 20);
textBox1.Text = "";

button1.Location = new Point(128, 104);
button1.Name = "button1";
button1.Text = "Click Me";

label2.Location = new Point(88, 192);
label2.Name = "label2";

button1.Click += new System.EventHandler(button1_Click1a);

//Controls.AddRange(new Control[]
//{label2, button1, textBox1, label1});
//Instead of this u can use the Following

Controls.Add(label2);
Controls.Add(label1);
Controls.Add(button1);
Controls.Add(textBox1);
}
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click1a(object sender, System.EventArgs e)
{
label2.Text = "Thanks a Lot ";
}
}

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!