Focus() in Control vs. UserControl

M

milund

Hi,

I am in the process of writing a custom control. In the OnMouseDown
method I call this.Focus() to enable the control to receive keystrokes
in OnKeyDown(). My control is hosted in a MDI form.

Originally my control inherited from UserControl, but then the call to
this.Focus() returned false and no keypresses were received. The I
changed it to inherit from Control and everything works as expected.

Why doesn't it work when I inherit from UserControl?

thanks,
Michael
 
K

Kevin Spencer

UserControl is a container Control, which is designed to host other Controls
in a composite form.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
M

milund

So it is in this case correct to inherit from control - the reason for
inheriting from a usercontrol is simply that is what I was given by a
wizard I ran, so I never gave it mouch thought until I ran into
problems ;-)

Thanks for the answer.
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top