This page contains a number of C# codes for the Amateur/Beginners in the Visual C# and .Net PlatForm Environment.
This tutorial will take anyone from the scratch to a good Windows Form creator although I am still learning at my spare time.
Source Code
-
-
- using System;
- using System.Drawing;
- using System.WinForms;
- class MyForm : System.WinForms.Form
- {
- public MyForm()
- {
- }
- public static void Main()
- {
- Application.Run(new MyForm());
- }
- }
-
-
-
-
-
Output
Source Code
-
-
- using System;
- using System.Drawing;
- using System.WinForms;
- class MyForm : System.WinForms.Form
- {
- public MyForm()
- {
-
- this.Text = "Form Tutorial No.2 From JAYANT";
- }
- public static void Main()
- {
- Application.Run(new MyForm());
- }
- }
-
-
-
-
-
Output
Source Code
-
-
- using System;
- using System.Drawing;
- using System.WinForms;
- class MyForm : System.WinForms.Form
- {
- public MyForm()
- {
-
- this.Text = "Form Tutorial No.3 From JAYANT";
- this.StartPosition = FormStartPosition.CenterScreen;
- this.AutoScaleBaseSize = new Size(5, 13);
- this.ClientSize = new Size(400, 200);
- this.MinTrackSize = new Size(400, (200 + SystemInformation.CaptionHeight));
- this.MaximizeBox = false;
- }
- public static void Main()
- {
- Application.Run(new MyForm());
- }
- }
-
-
-
-
-
Output
Source Code
-
-
- using System;
- using System.Drawing;
- using System.WinForms;
- class MyForm : System.WinForms.Form
- {
- Label label1;
- public MyForm()
- {
- label1 = new Label();
- label1.UseMnemonic = true;
- label1.Text = "First &Name:";
- label1.Location = new Point(15, 15);
- label1.BackColor = Color.Pink;
- label1.ForeColor = Color.Maroon;
- label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;
- label1.Size = new Size(label1.PreferredWidth, label1.PreferredHeight + 2);
-
- this.Text = "Form Tutorial No.4 From JAYANT";
- this.StartPosition = FormStartPosition.CenterScreen;
- this.AutoScaleBaseSize = new Size(5, 13);
- this.ClientSize = new Size(300, 200);
- this.MinTrackSize = new Size(300, (200 + SystemInformation.CaptionHeight));
- this.AutoScroll = true;
- this.MaximizeBox = false;
- this.Controls.Add(label1);
- }
- public static void Main()
- {
- Application.Run(new MyForm());
- }
- }
-
-
-
-
-
Output
Source Code
-
-
- using System;
- using System.Drawing;
- using System.WinForms;
- class MyForm : System.WinForms.Form
- {
- Label label1;
- public MyForm()
- {
- label1 = new Label();
- label1.UseMnemonic = true;
- label1.Text = "First &Name:";
- label1.Location = new Point(15, 15);
- label1.BackColor = Color.Pink;
- label1.ForeColor = Color.Maroon;
- label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;
- label1.Size = new Size(label1.PreferredWidth, label1.PreferredHeight + 2);
-
- this.Text = "Form Tutorial No.5 From JAYANT";
- this.StartPosition = FormStartPosition.CenterScreen;
- this.AutoScaleBaseSize = new Size(5, 13);
- this.ClientSize = new Size(300, 200);
- this.MinTrackSize = new Size(300, (200 + SystemInformation.CaptionHeight));
- this.AutoScroll = true;
- this.MaximizeBox = false;
- this.Controls.Add(label1);
- this.Click += new EventHandler(clicking);
- }
- public void clicking(object ob, EventArgs e)
- {
- MessageBox.Show("You clicked on Form Area");
- }
- public static void Main()
- {
- Application.Run(new MyForm());
- }
- }
-
-
-
-
-
Output
Source Code
-
-
- using System;
- using System.Drawing;
- using System.WinForms;
- class MyForm : System.WinForms.Form
- {
- Label label1;
- public MyForm()
- {
- label1 = new Label();
- label1.UseMnemonic = true;
- label1.Text = "First &Name:";
- label1.Location = new Point(15, 15);
- label1.BackColor = Color.Pink;
- label1.ForeColor = Color.Maroon;
- label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;
- label1.Size = new Size(label1.PreferredWidth, label1.PreferredHeight + 2);
-
- this.Text = "Form Tutorial No.6 From JAYANT";
- this.StartPosition = FormStartPosition.CenterScreen;
- his.AutoScaleBaseSize = new Size(5, 13);
- this.ClientSize = new Size(300, 200);
- this.MinTrackSize = new Size(300, (200 + SystemInformation.CaptionHeight));
- this.AutoScroll = true;
- this.MaximizeBox = false;
- this.Controls.Add(label1);
- this.Click += new EventHandler(clicking);
- }
- public void clicking(object ob, EventArgs e)
- {
- MessageBox.Show("You clicked on Form Area", "Title_JAYANT");
- }
- public static void Main()
- {
- Application.Run(new MyForm());
- }
- }
-
-
-
-
-
Output
Source Code
-
-
- using System;
- using System.Drawing;
- using System.WinForms;
- class MyForm : System.WinForms.Form
- {
- Label label1;
- public MyForm()
- {
- label1 = new Label();
- label1.UseMnemonic = true;
- label1.Text = "First &Name:";
- label1.Location = new Point(15, 15);
- label1.BackColor = Color.Pink;
- label1.ForeColor = Color.Maroon;
- label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;
- label1.Size = new Size(label1.PreferredWidth, label1.PreferredHeight + 2);
-
- this.Text = "Form Tutorial No.7 From JAYANT";
- this.BackColor = Color.BurlyWood;
- this.StartPosition = FormStartPosition.CenterScreen;
- this.AutoScaleBaseSize = new Size(5, 13);
- this.ClientSize = new Size(300, 200);
- this.MinTrackSize = new Size(300, (200 + SystemInformation.CaptionHeight));
- this.AutoScroll = true;
- this.MaximizeBox = false;
- this.Controls.Add(label1);
- this.Click += new EventHandler(clicking);
- }
- public void clicking(object ob, EventArgs e)
- {
- MessageBox.Show("Click will change the Form Color", "Title_JAYANT");
- this.BackColor = Color.Red;
- }
- public static void Main()
- {
- Application.Run(new MyForm());
- }
- }
-
-
-
-
-
Output
Source Code
-
-
- using System;
- using System.Drawing;
- using System.WinForms;
- class MyForm : System.WinForms.Form
- {
- Label label1;
- TextBox txtbx1;
- Button btn1;
- Button exit;
- public MyForm()
- {
- label1 = new Label();
- txtbx1 = new TextBox();
- btn1 = new Button();
- exit = new Button();
- label1.UseMnemonic = true;
- label1.Text = "First &Name:";
- label1.Location = new Point(15, 15);
- label1.BackColor = Color.Pink;
- label1.ForeColor = Color.Maroon;
- label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;
- label1.Size = new Size(label1.PreferredWidth, label1.PreferredHeight + 2);
- txtbx1.Text = "Enter Your Name";
- txtbx1.Location = new Point(15 + label1.PreferredWidth + 5, 15);
- txtbx1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;
- txtbx1.BackColor = Color.LightGray;
- txtbx1.ForeColor = Color.Maroon;
- txtbx1.Size = new Size(90, 20);
- btn1.Text = "&OK";
- btn1.Location = new Point(15 + txtbx1.Location.X + txtbx1.Size.Width, 15);
- btn1.Size = new Size(50, 20);
- exit.Text = "Exit";
- exit.Location = new Point(150, 150);
- exit.Size = new Size(90, 20);
- exit.BackColor = Color.Maroon;
- exit.ForeColor = Color.White;
-
- this.Text = "Form Tutorial No.8 From JAYANT";
- this.StartPosition = FormStartPosition.CenterScreen;
- this.AutoScaleBaseSize = new Size(5, 13);
- this.ClientSize = new Size(300, 200);
- this.MinTrackSize = new Size(300, (200 + SystemInformation.CaptionHeight));
- this.AutoScroll = true;
- this.MaximizeBox = false;
- this.Controls.Add(label1);
- this.Controls.Add(txtbx1);
- this.Controls.Add(btn1);
- this.Controls.Add(exit);
- btn1.Click += new EventHandler(Btn_Clicked);
- exit.Click += new EventHandler(Ext_Clicked);
- }
- public void Btn_Clicked(object ob, EventArgs e)
- {
- if (txtbx1.Text == "Enter Your Name")
- MessageBox.Show("You Have'nt Entered Your Name", "Title_JAYANT");
- else
- MessageBox.Show("Hello!!! " + txtbx1.Text, "Title_JAYANT");
- }
- public void Ext_Clicked(object ob, EventArgs e)
- {
- Application.Exit();
- MessageBox.Show("Successfully Closed", "EXIT");
- }
- public static void Main()
- {
- Application.Run(new MyForm());
- }
- }
-
-
-
-
-
Output