VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Make Windowless, Transparent UserControls Clickable

by Jeffry O'Neil ()
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 25th September 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Make Windowless, Transparent UserControls Clickable

Rate Make Windowless, Transparent UserControls Clickable



Microsoft has documented a problem with windowless User-Controls that have a transparent Backstyle. Once a form contains such a control, you can't select it by clicking on it with the mouse; this makes it tough to move the control. (See Microsoft Knowledge Base article Q188234 for details.) Use this code workaround that allows you to click on and move these controls at design time. First, it uses the HitTest event to make the control always act as if it is clicked, regardless of mouse coordinates. This usage causes the UserControl_Click event to fire, which the owner can observe through the raised Click event: 
Private Sub UserControl_HitTest(X As Single, Y _
As Single, HitResult As Integer)
' Always act as if the control was hit
If HitResult = vbHitResultOutside Then
HitResult = vbHitResultHit
End If
End Sub
Public Event Click()
Private Sub UserControl_Click()
' Let the form handle the click
RaiseEvent Click
End Sub

In production code, if only portions of the control should be clickable in run mode, test for design mode vs. run mode in the HitTest event. Use this method only in design mode, and your own custom test in run mode.  


Download this snippet    Add to My Saved Code

Make Windowless, Transparent UserControls Clickable Comments

No comments have been posted about Make Windowless, Transparent UserControls Clickable. Why not be the first to post a comment about Make Windowless, Transparent UserControls Clickable.

Post your comment

Subject:
Message:
0/1000 characters