Sponsored Ad

Monday, September 28, 2009

C# Winform

Windows Forms is a graphical user interface appliance programming interface (API) included as a allotment of Microsoft's .NET Framework. As of 13 May 2008, Mono's System.Windows.Forms 2.0 is API complete. Simply put, Winforms is a library for creating GUI applications.

This program is for beginners who want to learn the basics of C# WinForms. The following code gives a quick and easy 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 ";
}
}

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers