Hi All
I have a custom form that I use for notification popups and wanted to add some shadow or glow around the edge. I managed to get something working after working out how to create a transparent form. Unfortunately when the Invalidate is called to repaint the transparency is removed.
In the Form.New I setup the styles like so
I setup the CreateParams property to add transparent WS_EX_TRANSPARENT=&H20
In the OnPaint of the form I create a graphics path and build up smaller and smaller shapes with gradually increasing ARGB values for the color
This gives me a transparent form in the shape I want.

I can then paint a gradient brush to get the form I'm after.

If the Invalidate is called so OnPaint redraws I seem to lose the transparency.

I've seen a lot of posts where people have tried doing shadows with limited success. I was after a method where I could set the color or width of the shadow/glow which is why I tried this method. Many have said WinForms and shadows don't go together well and to use WPF?
Anyway if someone has a better method or knows why I lose the transparency I would be grateful.
Cheers
Peter
I have a custom form that I use for notification popups and wanted to add some shadow or glow around the edge. I managed to get something working after working out how to create a transparent form. Unfortunately when the Invalidate is called to repaint the transparency is removed.
In the Form.New I setup the styles like so
VB.NET:
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque Or ControlStyles.UserPaint Or ControlStyles.SupportsTransparentBackColor, True)
I setup the CreateParams property to add transparent WS_EX_TRANSPARENT=&H20
VB.NET:
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cParam As CreateParams = MyBase.CreateParams
cParam.ClassStyle = cParam.ClassStyle Or WS_EX_TRANSPARENT
Return cParam
End Get
End Property
In the OnPaint of the form I create a graphics path and build up smaller and smaller shapes with gradually increasing ARGB values for the color
VB.NET:
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
If e Is Nothing Then Throw New ArgumentException("e")
MyBase.OnPaint(e)
_Shape = BuildPath(Me.ClientRectangle)
Me.Region = RegionFromPath(_Shape)
Location = BalloonLocation
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
Dim rect As Rectangle
Dim sb As SolidBrush
For i As Integer = 0 To 6
rect = New Rectangle(New Point(i, i), New Size(BalloonSize.Width - i * 2, BalloonSize.Height - i * 2))
_Shape = BuildPath(rect)
e.Graphics.DrawPath(New Pen(New SolidBrush(Color.FromArgb(24 * i, Color.Black))), _Shape)
Next
End Sub
This gives me a transparent form in the shape I want.

I can then paint a gradient brush to get the form I'm after.

If the Invalidate is called so OnPaint redraws I seem to lose the transparency.

I've seen a lot of posts where people have tried doing shadows with limited success. I was after a method where I could set the color or width of the shadow/glow which is why I tried this method. Many have said WinForms and shadows don't go together well and to use WPF?
Anyway if someone has a better method or knows why I lose the transparency I would be grateful.
Cheers
Peter