Atmocreations
Atmocreations

Reputation: 10061

Remove ability of a Usercontrol to get focus

while designing my user control, i encountered the following problem:

i would like to set the UserControl.CanGetFocus to false, which is not possible due an error message telling me that a control unable to receive focus can not contain elements who are able to receive focus.

but as i don't want them to actually receive any focus, i would like to disable this for the child-objects as well as for my user control. i can barely believe that there's no possiblity to prevent the child-controls to receive focus, no matter of what type they are? i currently use imageboxes and pictureboxes.

already searched using google, always leading to the result that the property cannot be set to false under these conditions...

Upvotes: 1

Views: 2290

Answers (6)

Darrel Miller
Darrel Miller

Reputation: 142014

If you put the picturebox in a frame and the disable the frame then it will not receive mouse events. Doing this in combination with setting the tabstop to false will prevent the picturebox from receiving focus.

I've used this technique in the past to create a checkbox usercontrol that can be made read-only.

Upvotes: 2

RBarryYoung
RBarryYoung

Reputation: 56725

It's been a while, but the solution to this that we used for years was to catch the received-focus event (sorry, can't remember what it is) and then explicitly force th focus to something else. It's kludgey, and not easy (because of the vagaries of event-ordering and reordering in VB/Com Windows), but it got the job done.

Upvotes: 0

AngryHacker
AngryHacker

Reputation: 61596

You might want to look at this article.

http://support.microsoft.com/kb/180216

Sounds like you have a problem. The only known workaround is to set the UserControl's Enabled property to False instead of setting the CanGetFocus property. But then, of course you would not be able to respond to clicks and things.

Upvotes: 0

shahkalpesh
shahkalpesh

Reputation: 33476

You can set the TabStop property of the childcontrol to False.

Upvotes: 1

Beth
Beth

Reputation: 9607

Can you set an enabled property to false?

Upvotes: 0

Mike Burton
Mike Burton

Reputation: 3020

Have you tried just using Image controls? If I recall correctly they're lightweight and shouldn't capture focus, whereas a PictureBox is always going to be able (in theory) to capture focus. Depending on your need, this may be sufficient.

Upvotes: 0

Related Questions