Click here to Skip to main content
11,711,887 members (73,912 online)
Rate this: bad
good
Please Sign up or sign in to vote.
i must create a keypress event on design time. how can i do this??? i want to make an event which should be handled without starting debugging. i mean i created an user control and when i press F1 key, it will open a help file about the control on Form1[Design].
Posted 31-Jul-12 21:42pm
thoahn581
Edited 31-Jul-12 23:43pm
v3
Comments
efkah at 1-Aug-12 4:01am
   
can you elaborate?
i have a feeling you're thinking too complicated.
WPF, WinForm or ASP.NET?
thoahn at 1-Aug-12 4:16am
   
i say for winform bro
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Depends: if you are talking about adding an event to your class that users of your class can handle, then it's pretty easy - just add the code:
/// <summary>
/// Event to indicate [Description]
/// </summary>
public event EventHandler Name;
/// <summary>
/// Called to signal to subscribers that [Description] occured
/// </summary>
/// <param name="e"></param>
protected virtual void OnName(EventArgs e)
    {
    EventHandler eh = Name;
    if (eh != null)
        {
        eh(this, e);
        }
    }
If you are talking about adding a handler to an existing event, then just highlight the object in the designer and:
Look at the Properties pane.
Press the Events button - it looks like a lightening bolt.
Find the event you want to handle.
Double click it.

That will add the handler, and a bare-bones handler routine for you to fill in.

If you are often going to create events it might be worth your looking at this: A simple code snippet to add an event[^]
It makes it a lot easier to generate the above code!
  Permalink  
Comments
thoahn at 1-Aug-12 4:14am
   
Actually i want to make an event which should be handled without starting debugging. i mean i created an user control and when i press F1 key, it will open a help file about the control on Form1[Design].
Thanx anyway bro.
OriginalGriff at 1-Aug-12 4:22am
   
Then ask that in your question! :laugh:
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please go through the links below to know the implementation of KeyPress Event.
how to use keypress events[^].
Keyboard Event Handling: onkeypress
[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CHill60 280
1 Sergey Alexandrovich Kryukov 264
2 Andy Lanng 160
3 OriginalGriff 130
4 Richard MacCutchan 130
0 CHill60 280
1 Sergey Alexandrovich Kryukov 125
2 Andy Lanng 120
3 Abhinav S 95
4 Maciej Los 95


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100