I’ve got a control that derives from Forms.Control, it handles mouse events and paint events just fine, but I’m having a problem with key events. I need to handle Left arrow and Right arrow, but so far the Tab control that contains my class eats these.
How do I make this control selectable, focusable?
Here is a nice tutorial to make a focusable control. I just followed it to make sure it works. Also, added a keypress event to the control which works on condition that the control has focus.
http://en.csharp-online.net/Architecture_and_Design_of_Windows_Forms_Custom_Controls%E2%80%94Creating_a_Focusable_Control
Basically all I did was make an instance of my custom control, which inherits from Control. Then added KeyPress, Click, and Paint event. Key press was just a message:
Click event just has:
The paint event I made like this, just so it was visible:
Then, in the main form, after making an instance called mycustomcontrol and adding the event handlers:
The example is much neater than my five minute code, just wanted to be sure that it was possible to solve your problem in this way.
Hope that was helpful.