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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transparent label on a transparent UserControl

Status
Not open for further replies.

robdon

Programmer
May 21, 2001
252
0
0
ES
Hi,

If you create a UserControl and make the BackStyle Transparent and then place a label control with a caption in it onto to the UserControl (as part of the UserControl) and make the label also Transparent, then if you place this UserControl on a form, the labels caption is not visible.

Any ideas why, or how to overcome this?

Thanks,

Rob D.

ProIV Resource Centre
 
Also, the .Print method of the UserControl does not work when the UserControl is transparent.

It seems to 1/2 work if the font is set to 'Courier', but it looks all distorted.

Rob D.

ProIV Resource Centre
 
Ok, learnt a bit more, but still cant quite get it right.

To get the .Print to work you have to set the MaskColor to vbButtonFace and then put this line after the .Print:

UserControl.Cls
UserControl.Print "This is a pain in the ^&%!"
UserControl.MaskPicture = UserControl.Image

Now that prints the text all ok now, but the MouseMove event doesnt seem to be firing correctly.

It seems to only fire when the mouse is over a pixel that is in the text. Any transparent area seems to pass through the usercontrol and gets picked up by the forms MouseMove event.

So.... any ideas on how to fix the MouseMove bit?

Thanks,

Rob D.

ProIV Resource Centre
 
Some more....

If you set the UserControl 'Windoweless' property to True and put the following into the UserControl_HitTest event:

If HitResult = vbHitResultOutside Then
HitResult = vbHitResultHit
End If

And also put the following after the MaskPicture line from above:

UserControl.Picture = UserControl.Image

Then it seems to work correctly.

The only problem is that now that the UserControl is Windowless I cant have any controls on it, but thats not too much of a problem because I was mostly Painting my controls anyway.

Sorry for all the rambling, maybe someone will find it of use because it sure was hard to find stuff on google for this kind of thing. Lots of people have tried to write Transparent Label controls but the ones I found never worked 100%.

Now I'm happy :)

Rob D.

ProIV Resource Centre
 
Sorry, forgot to mention also, set the UserControl BackColor to vbButtonFace & BackStyle to Transparent....

ProIV Resource Centre
 
Well, it seems to me like perhaps the reason that you're doing this is because you want the usercontrol's backcolor to conform to its container's backcolor. If that's so, it's easy. In the UserControl_ReadProperties event handler, put this line of code:
Code:
UserControl.BackColor = Ambient.BackColor
This will cause your usercontrol to adopt the color of its container. Of course, if you're doing it because you want to overlay a picture or something, that's a different matter.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top