Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 31-Jul-12 23:43pm
v3
Comments
efkah 1-Aug-12 4:01am    
can you elaborate?
i have a feeling you're thinking too complicated.
WPF, WinForm or ASP.NET?
thoahn 1-Aug-12 4:16am    
i say for winform bro

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:
C#
/// <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!
 
Share this answer
 
Comments
thoahn 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 1-Aug-12 4:22am    
Then ask that in your question! :laugh:
Please go through the links below to know the implementation of KeyPress Event.
how to use keypress events[^].
Keyboard Event Handling: onkeypress
[^].
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900