Key Related Events in C# .Net

Ratings:
(4)
Views:165
Banner-Img
  • Share this blog:

 

Key Related Events

  1. KeyPress
  2. Key down
  3. Key Up

 The difference between Keypress and Key down:

  • In key press, logic will be executed Before displaying a character
  • In key down, logic will be executed After displaying a character
  • Key board character are divided into two types:-

  Screenshot_70  

 

Interested in mastering .NET? Learn more about ".NET Training "in this blog post.

Example of developing a Ball and Bat game:

Screenshot_71    

  • Open WFAP
  • Place a Label control arrrow properties arrrow

Back  Color = black Auto Size  = false Location  = 202, 440 Left,    top

  • Place a Picture Box Control arrrow Properties arrrow

Image = Select an image Size mode  = Stretch image Location  = 13, 200 Left,    top

  • Place a Timer with Enabled = true;
  • Place one more Timer with Enabled = false
  • Code for Form1_Keydown event
{

Int I = (int) e.  keycode;

//Message Box. Show (I + “”);

If ((I = = 37)  && Label1.left > 0 )

Label 1.left = Label1.left -3;

If ((I = = 39)  && Label1.left < this. Width - 100 )

Label 1.left = Label1.left +3;

}
  • Code for Timer 1 _ Tick Event
{

Picture Box. Top = Picture Box 1. Top – 15;

If (Picture Box. Top  < 0)

{

Timer 1. Enabled = false;

Timer 1. Enabled = true;

}

Code for Timer 2 _ Tick Event

{

Picture Box1. Top = Picture Box 1. Top +5;

Picture Box2. Left = Picture Box 1. Left +1;

If  (Picture Box1. Top = Label1.Top && Picture Box1.left  >Label1.left && Picture Box1. Left  < Label1.right )

{

Timer 1.enabled = true;

Timer 2.enabled = false;

}

  Screenshot_72    

2.Every item will be identified with a unique index number which tarts always from zero.  

Screenshot_73  

  1. Como box allows to select only one item at a time
  2. The list box allows to select multiple items also.

 

Check Out .Net Tutorial

Common Properties and methods of list box and combo box:- 

Properties:-  

  1. Items arrrowused to add items at design time
  2. Selected item
  3. Selected Index

  Methods: -

  Screenshot_74  

  1. Combo box1. Items Add (String)
  2. Combo box1. Items Insert(index, String)
  3. Combo box1. Items Remove(String)
  4. Combo box1. Items Remove(index)
  5. Combo box1. Items clear();
  6. Combo box1. Items Index of (String)
  7. Combo box1. Items Countà(property)
  8. Combo box1. Items Get Enumerator ();  

 Example on combo box:-

A program to change the shape of  a FORM

  Screenshot_75  

Namespace arrrowSystem Drawing. Drawing 2 D

Screenshot_76

  • Open WFAP
  • Place a combo box arrrowproperties arrrow Items = add

 

  • Using System . Drawing . Drawing 2 D;
  • Code for combo box 1 _ Selected Index changed Event

  Graphics path g = new Graphics path ();

Int I = combo box 1. Selected index;

If  (I = = 0) //circle

  1. Add Ellipse (10, 10, 150, 150) ;

else if (i ==1 ) //ellipse

  1. Add Ellipse (10, 10, 150, 400) ;

else //triangle {

  1. Add Line (10, 10, 200, 300) ;
  2. Add Line (200, 300, 100, 150) ;
  3. Add Line (100, 150, 10,10) ;

} Screenshot_78    

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

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.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox