Windows and Web Applications
Chapter 7
Introduction
GUI Components
WinForms
ToolBox in Microsoft Visual Studio.NET
Important Controls
1.Button
2.Check Box
3.Check List Box
4.ComboBox
5.DateTimePicker
6.Label
7.Link Label
8.List Box
9.List View
10.Month Calendar
11.Radio Button
12.Text Box
Forms
System.Windows.Forms
Form Properties
Forms Methods
Event Handling Model
Example
Basic Event Handling
private void FormName_Click (Object sender,System.EventArgs e) { }
This is the method that will be called when the form is clicked .
private void FormName_Click (Object sender , System.EventArgs e)
{ MessageBox.Show(“Form was pressed “);
}
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
Public dlass MyForm : System.Windows.Forms.Form
{ private System.ComponentModel.Container Components = null ;
static void Main()
{ Application.Run(new MyForm());
}
private void MyForm_Click (Object sender , System.EventsArgs e)
{ MessageBox.Show(“Form was Pressed”);
}
}
void ControlName _ EventName (Object sender ,EventArgs e)
{
event handling code ;
}
Registering an event
Control Common Properties
Control Common Methods
Anchoring
Anchoring ----
Docking Demonstration
Control Layout Properties
using System;
using System.Window.Forms;
using System.Drawing;
namespace Ex1
{ class Test
{ static void Main() { Application.Run(new MyWindow()); }
class MyWindow:Forms
{ public MyWindow() : base()
{ this.Text = “My First windows Application “;
this.size = new size(300,300);
label lblGreeting = new Label();
lblGreeting.Text = “HellWinForm “;
lblGreeting.Location = new Point(100,100);
this.Controls.Add (lblGreeting);
}
}
}
namespace Ex2
{ class Test
{ static void Main() { Application.Run(new MyWindow()); }
class MyWindow:Forms
{ public MyWindow() : base()
{ this.Text = “My First windows Application “;
this.size = new size(300,300);
this.StartPosition = FormStartPosition.CenterScreen;
//label
label lblGreeting = new Label();
lblGreeting.Text = “HellWinForm “;
lblGreeting.Location = new Point(100,100);
//Button
Button btnExit = new Button();
btnExit.Text = “Exit”;
btnExit.Location = new Point(180,180);
btnExit.Size = new Size(80,30);
btnExit.Click + = new EventHandler(BtnExitOnClick);
this.Controls.AddRange(new Control[] { lblGreeting ,btnExit});
}
public void BtnExitOnClick(Object sender ,EventArgs e)
{ Application.Exit();
}
} }
Labels ,Text Boxes and Buttons
Label Properties
Text Box
Button
Group Boxes and Panels
CheckBoxes and RadioButtons
Any number may be selected at a time. The text that appears alongside a checkbox is referred to as the checkbox label.
PictureBoxes
Mouse Event Handling
Keyboard Event Handling