Click here to Skip to main content
12,948,566 members (63,122 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
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
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 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:
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
Top Experts
Last 24hrsThis month
OriginalGriff 5,419
CHill60 3,275
Maciej Los 2,778
Jochen Arndt 1,935
ppolymorphe 1,795


Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2017
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