views:

526

answers:

6

hello

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...

any idea is appreciated.

thanks in advance and best regards

atmocreations

A: 

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.

Mike Burton
though a good idea, but a thought i've already had: i need to owner parts of the control. for this i need a device context, therefore a picturebox is required. any way to keep the picturebox from accepting the focus?
Atmocreations
A: 

Can you set an enabled property to false?

Beth
of the user control? ermm no, as click and other events should still be evaluated...
Atmocreations
+1  A: 

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

shahkalpesh
is an idea. but this unfortunately doesn't solve the problem. as the focus can still be accepted by mouse-events. :(
Atmocreations
A: 

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.

AngryHacker
Frustratingly the article is for VB5. No sign of an article that mentions VB6.
MarkJ
A: 

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.

RBarryYoung
+2  A: 

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.

Darrel Miller
good idea. but this technique also disables the click-event of that region to be raised, which would be required... well i could paste something invisible like a label to receive the event...have to check whether the picturebox still draws when its disabled.
Atmocreations
well... it's a very dirty but still the best solution to solve my problem. many thanks to you all who contributed. regards
Atmocreations