Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Advanced
Apr 7, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.
Don Benson
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date