Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent picturebox clicks from stealing focus

Status
Not open for further replies.

Punchinello

Programmer
Apr 25, 2003
116
US
If I use a picture box as a container for user controls and click the mouse in an empty region of the picture box, focus leaves the active control and goes - I assume - to the picture box itself. Can anyone suggest a way to make the picture box ignore mouse clicks?
 
Set the "Enabled" property to False?
 
Golom,
setting Enabled to false prevents access to the child controls. Thanks for the reply but that won't work.
 
Maybe have the control you wish to keep the focus on have the subroutine LostFocus set the focus on it once more.

Private Sub Form_LostFocus()
Me.SetFocus()
End Sub
 
JBlair,

I've actually developed routines on one form that uses the GotFocus event on each user control to set the tag property of its PictureBox parent like so:
Code:
Private Function NewFocus
Dim Ctrl As Control
  Set Ctrl = Me.ActiveControl
  MyPictureBox.Tag = Ctrl.Name
End Function

Private Sub MyControl_GotFocus()
  NewFocus
End Sub
The effect of the code above is simply to store the name of the last user control that was active. Then on the PictureBox's GotFocus event, I implement code like in your suggestion to return the focus to the "last active" control:
Code:
Private Sub MyPictureBox_GotFocus()
On Error Resume Next
  Me.Controls(MyPictureBox.Tag).SetFocus
End Sub
This code works fine. What I was hoping for was the suggestion of an API call or some code that I can apply to the PictureBox all by itself without having to fuss with every other control's GotFocus event. In Delphi, for example, I can trap an event like MouseDown and silently abort it with a command called (not surprisingly) Abort.
 
I know very little about API's but perhaps you can find something by browsing the lists of the API viewer?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top