An Easy Way to Create a Transparent Form !
I provide an easy to create the non-rectangle form with usercontrol. We may use the control to design a non-rectange form or a desktop animation easily.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
Now you can test the code in following steps:
1) Create a new Visual Basic project
2) Add the UserControl to your project and named it as 'TransparentCtrl'
3) Add the following code to the control
' Start Control Code
Public Property Get MaskPicture() As Picture
Set MaskPicture = UserControl.MaskPicture
End Property
Public Property Set MaskPicture(ByVal picNew As Picture)
Set UserControl.MaskPicture = picNew
'Put the Refresh() code before the Set Picture Property will
'have better effection
Me.Refresh
Set UserControl.Picture = picNew
PropertyChanged "MaskPicture"
End Property
Public Property Get MaskColor() As OLE_COLOR
MaskColor = UserControl.MaskColor
End Property
Public Property Let MaskColor(ByVal clrMaskColor As OLE_COLOR)
UserControl.MaskColor = clrMaskColor
Me.Refresh
PropertyChanged "MaskColor"
End Property
'Refresh() to changed the container region with usercontrol's
Public Sub Refresh()
'On Local Error Resume Next
Dim hRgnNormal As Long
With UserControl
If .MaskPicture = 0 Then
hRgnNormal = CreateRectRgn(0, 0, .ScaleX(.Width), .ScaleY(.Height))
SetWindowRgn .Extender.Container.hWnd, hRgnNormal, True
Else
.Size .ScaleX(.MaskPicture.Width), .ScaleY(.MaskPicture.Height)
.Extender.Container.Width = .Width
.Extender.Container.Height = .Height
.Extender.Move 0, 0
'Gwyshell
'Let the system have time to finish the special regions created
DoEvents
'Set New Regions
SetWindowRgn .Extender.Container.hWnd, Me.hRgn , True
If Err Then
MsgBox "The Container not support the mothods"
End If
End If
End With
End Sub
Public Property Get hRgn() As OLE_HANDLE
hRgn = CreateRectRgn(0, 0, 1, 1)
GetWindowRgn Me.hWnd, hRgn
End Property
'Following code to persist the control's property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Me.MaskColor = PropBag.ReadProperty("MaskColor", &H8000000F)
Set Me.MaskPicture = PropBag.ReadProperty("MaskPicture", Nothing)
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "MaskColor", Me.MaskColor, &H8000000F
PropBag.WriteProperty "MaskPicture", Me.MaskPicture, Nothing
End Sub
' End of Control Code
4) Now close the UserControl Designer to make the control active.
Add the control on the form and assign the mask picture and mask color
to the control.
5) After this, you may see the region of the form has been changed.
To get the full code please visit here:
http://www.mgt.ncu.edu.tw/~im841150/Documents/TransparentCtrl/TransparentCtrl.htm
Upload
Original Comments (3)
Recovered from Wayback Machine