[RESOLVED] Drawing on UserControl with Transparent BackStyle.
I am trying to draw on a UserControl, but I want to have other regions apart from my drawing transparent, so the Background/Controls on the Form should be visible apart from my drawing when the UserControl is over them. As of now when I set the BackStyle Opaque the drawing is visible but when I change it to transparent it is not.
Code:
Private Sub UserControl_Initialize()
UserControl.BackStyle = 0 '0=Transparent 1=Opaque
Line (200, 200)-(800, 800), RGB(0, 0, 0), BF
End Sub
2 Attachment(s)
Re: Drawing on UserControl with Transparent BackStyle.
Easy enough, but there are limits to what you can do during a UserControl's Initialize event. For one thing the control isn't fully created yet, and even during InitProperties/ReadProperties it is not fully sited yet.
You can trap and do this during the first Show event and often in the Resize event. For example:
Code:
Option Explicit
Private Sub Draw()
AutoRedraw = True
Cls
FillStyle = vbFSTransparent
DrawWidth = 1
DrawStyle = vbDot
Line (0, 0)-(ScaleWidth - 15, ScaleHeight - 15), vbRed, B
DrawStyle = vbSolid
DrawWidth = 3
Line (180, 180)-(ScaleWidth - 180, ScaleHeight - 180), vbCyan, B
DrawWidth = 7
Line (420, 420)-(ScaleWidth - 420, ScaleHeight - 420), vbBlack
FillStyle = vbDiagonalCross
FillColor = vbBlue
DrawWidth = 8
Line (420, Int(ScaleHeight / 2))-(Int(ScaleWidth / 2), ScaleHeight - 420), vbYellow, B
AutoRedraw = False
Set MaskPicture = Image 'Render with mask transparency.
End Sub
Private Sub UserControl_Initialize()
MaskColor = &HFEFEFE 'Some unique color we don't otherwise use.
BackColor = MaskColor
End Sub
Private Sub UserControl_Resize()
Draw
End Sub
However even at best there are issues with this simple form of transparent rendering, such as interference with ClearType font rendering for many display drivers:
Attachment 158325
Re: Drawing on UserControl with Transparent BackStyle.
This works:
thinBasic Code:
Option Explicit
'--- design-time settings
' UserControl.Windowless = True
' UserControl.ClipBehaviour = 0-None
Private Sub UserControl_Initialize()
UserControl.BackStyle = 0 '0=Transparent 1=Opaque
End Sub
Private Sub UserControl_Paint()
Line (200, 200)-(800, 800), RGB(0, 0, 0), BF
End Sub
Private Sub UserControl_HitTest(X As Single, Y As Single, HitResult As Integer)
HitResult = vbHitResultHit
End Sub
cheers,
</wqw>
Re: Drawing on UserControl with Transparent BackStyle.
Quote:
Originally Posted by
software07
...Controls on the Form should be visible apart from my drawing when the UserControl is over them. ...
Quote:
Originally Posted by
wqweto
This works:
...
'--- design-time settings
' UserControl.Windowless = True
...
I'm pretty sure that a Windowless control can't be drawn over other controls (other than other windowless controls) so doesn't quite work as the OP specified.
Re: Drawing on UserControl with Transparent BackStyle.
Quote:
Originally Posted by
dilettante
Easy enough, but there are limits to what you can do during a UserControl's Initialize event. For one thing the control isn't fully created yet, and even during InitProperties/ReadProperties it is not fully sited yet.
You can trap and do this during the first Show event and often in the Resize event. For example:
Code:
Option Explicit
Private Sub Draw()
AutoRedraw = True
Cls
FillStyle = vbFSTransparent
DrawWidth = 1
DrawStyle = vbDot
Line (0, 0)-(ScaleWidth - 15, ScaleHeight - 15), vbRed, B
DrawStyle = vbSolid
DrawWidth = 3
Line (180, 180)-(ScaleWidth - 180, ScaleHeight - 180), vbCyan, B
DrawWidth = 7
Line (420, 420)-(ScaleWidth - 420, ScaleHeight - 420), vbBlack
FillStyle = vbDiagonalCross
FillColor = vbBlue
DrawWidth = 8
Line (420, Int(ScaleHeight / 2))-(Int(ScaleWidth / 2), ScaleHeight - 420), vbYellow, B
AutoRedraw = False
Set MaskPicture = Image 'Render with mask transparency.
End Sub
Private Sub UserControl_Initialize()
MaskColor = &HFEFEFE 'Some unique color we don't otherwise use.
BackColor = MaskColor
End Sub
Private Sub UserControl_Resize()
Draw
End Sub
However even at best there are issues with this simple form of transparent rendering, such as interference with ClearType font rendering for many display drivers:
Attachment 158325
Thanks it worked perfectly.