Action on control is called an “Event”.
In C #. Net, always events take two arguments
Always the first argument will be an object but the second argument type may vary from event to event. C #.net events are divided into 4 groups
Mouse Related events
Focus Related events
Drag Related events
Key Related events
Mouse Related Events
Click
Double click
Mouse up
Mouse Down
House leave
House enter
Mouse More
Mouse Mover: this event will be fired when the mouse pointer placed on the control for some time.
Interested in mastering .NET? Learn more about ".NET Training" in this blog post.
A program to use the company logo as the mouse pointer
Open windows form 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
String S = “MICRO SOFT TECHNOLOGIES”
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);
Leave: This event will be executed while the cursor is coming out from control.
Enter: This event will be executed while the cursor is Entering into control.
Note:- Generally these events will be used in Data Validations
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 “);
Else 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 needs to be displayed.
Arg 2: Error Message, if this is empty, then blinking Icon will Will not be displayed.
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 into .net text box.
Open WFAP 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;
}
else
Message Box. Show (“Not valid”);
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.