A VB.NET Winform DropShadow demo by Simonetos The Greek.
The initial idea started from a question at stackoverflow.com titled "Windows 7 style Dropshadow in borderless form" by Corylulu. Then, Wener made a workable class in C# which you can find it here. I managed to translate this class to a workable VB.NET class and also add the Shadow Radius ability. I also made the demo a bit easier to use and a bit more good looking.
By including this class into your VB.NET Winforms...
- Basically, you can give shadow to a borderless form.
- You can make form's shadow size as big as you want.
- You can set shadow's horizontal and vertical position using negative and positive values.
- You can make form's shadow looks blurred.
- You can change shadow's color and opacity.
- And finaly, you can add shadow radius.
- You can also add form radius (manualy!!!).
Here is an example of how you can use DropShadow class into your form's code.
Public Class Form1
'((( Declare DropShadow class. )))
Public _Shadow As Dropshadow
'((( Add the necessary initializations for your form. )))
Public Sub New()
InitializeComponent()
Me.FormBorderStyle = FormBorderStyle.None
Me.DoubleBuffered = True
End Sub
'((( And here we go... )))
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not DesignMode Then
_Shadow = New Dropshadow(Me) With {
.ShadowH = 0,
.ShadowV = 0,
.ShadowBlur = 5,
.ShadowSpread = 5,
.Opacity = 128,
.ShadowColor = Color.FromArgb(CInt(.Opacity), 0, 0, 0),
.ShadowRadius = 0
}
_Shadow.RefreshShadow()
End If
End Sub
End Class
And how you can add form radius. You should do that manualy.
'((( Replace *** with a number of your choice. )))
Me.Region = Region.FromHrgn(Win32.CreateRoundRectRgn(0, 0, Me.Width + 1, Me.Height + 1, ***, ***))
_Shadow.RefreshShadow()
As you will see in Demo project, you should also manually do _Shadow.RefreshShadow()
every time that form changes state or size. For example, when form changes state from FormWindowState.Normal
to FormWindowState.Maximized
or when you resize the form using a resize handler.
You can find the DropShadow class file here.