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 IfEnd SubPublic Event Click()Private Sub UserControl_Click()	' Let the form handle the click	RaiseEvent ClickEnd 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.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS