Action on a control is called an “Event”.

In C #. Net, always events takes two arguments

Always first argument will be object but second argument type may vary from event to event.

C events are divided in to 4 groups

Mouse Related events

Focus Related events

Drag Related events

Key Related events

Mouse Related Events


Double click

Mouse up

Mouse Down

House leave.

House enter

Mouse More

Mouse Mover: this event will be fired , when mouse pointer placed on a control for some time.

A program to use company logo as mouse pointer

Open windows forms Application Project

Place a picture Box control àproperties

Image = Select an Image.

Size  Mode = Stretch Image

Code for Form1 Mouse More Event


Picture Box 1. Location = new Point  (e. x, e. y);

Cursor . Hide ();


Developing Animated Text

Open Windows Forms Application Project

Form àProperties àBack color  = Black

Place a button

Place a Timer with Enabled = false


Using System . Drawing .Drawing 2D


Code in GD



Font f = new  Font  (“Arial ”, 50);

Linear Gradient Brush  b = new   Linear  Gradient Brush    (new point  (100, 100), new Point  (200, 300), color. Red, color .yellow );

Int x =5;

Graphics g; // abstract class


Code for Button 1_ click


g = this .create Graphics ();

Draw String (S, f,b 10,10);

Timer 1. Enabled = true;



Code for Timer 1_Tick event


X = X+3;

If (X > 300)

X= 0;


Linear Gradient Brush   b1 = new  Linear  Gradient Brush     (new point  (100, 100), new Point  (x, 300), color. Red, color .yellow );


draw String (S, f,b, 10, 10);


Focus Related Events



Leave: This event will be executed while cursor is coming out from a control.

Enter: This event will be executed while cursor is Entering in to a control.


Note :-

Generally these events will be used in Data Validations


Example on Leave Event 



Open Windows Forms Application Project

Place two Labels and two text boxes as shown

Place error Provider control àProperties àBack Style = Always Blink

Code for Text Box1 Leave Event


If (text Box1. Text = “”)

Error Provider1. Set Error (text Box 1,”Eno should not be Empty “);


Error Provider1. Set Error (text Box 1,” “ .); // No Space



Error Provider1. Set Error () takes two arguments

Arg 1 : The control Name, after which a blinking  Icon need to be displayed.

Arg 2 : Error Message , if this  is empty , then  blinking  Icon will Will not be displayed.


Drag Related Events

C # supports four Types of Drag Related Events




To work  with Drag Related Events, ALLOW DROP property must be set to true.

Example: -

A program for dragging the data from MS – word in to .net text box.


Place a text box - - >  properties - - >  Allow drop = true Multiline = true scroll bars = both

Code for Text Box 1 Drag Enter Event


If  (e. data. Get data present  (Data Formats .Text)  == true)



String s = (String) . e. Data . Get Data (Data Formats. Text) ;

Text Box 1.Text = s;



Message Box. Show (“Not valid”);