Click here to Skip to main content
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 22:42pm
thoahn559
Edited 1-Aug-12 0:43am
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 Kornfeld Eliyahu Peter 275
1 Maciej Los 204
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 183
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2014
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