VB.NET Drop Shadow At The Form Border

this is something make your application attractive by the way this is a simple code that you have to place under public class form1

vb.net drop shadow

so here is the code

Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Const DROPSHADOW = &H20000
            Dim cParam As CreateParams = MyBase.CreateParams
            cParam.ClassStyle = cParam.ClassStyle Or DROPSHADOW
            Return cParam
        End Get
    End Property

and the shadow

vb.net drop shadow preview

13 comments

Stefan Wittwer mod

Thanks man, you're great!

Reply

&H20000: What this indicate in this Code:
And Can I add more Shadow?
And How?

I just try to make &H40000: but this show incorrect parameters...

please Explain the Codes

Reply

Hello

As you can see in the code it's a system style of forms System.Windows.Forms.CreateParams, we just create the parameter and if you change the value nothing will happen because &H20000 is a system value if you want to access Win32 registry key you use &H200000 etc because it's a system value by the way it's not possible to add more shadow by using this method since it's a system value but i recommend you to learn some GDI so you can create your own themes and etc ..

Thanks

Reply

Can you explain me more about GDI:
I really like your way...
Now as you told I can create my own new theme:
So i will really like to create a new theme :
But here I need somewhat help by you:

So please explain me in more details so that I can create my own theme....

Reply

Hi ,

Actually i am not into GDI i am sorry for that by the way if i get to know something about making themes i will surely write an article about it.

Thanks

Reply

Humm ,,, Just past the code and you will get the windows 7 Drop Shadow like this >>> http://marcin.floryan.pl/wp-content/uploads/2010/08/WPF-Window-native-shadow.png

Imports System.Runtime.InteropServices

Public Class IMSS_SplashScreen
Private aeroEnabled As Boolean
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
CheckAeroEnabled()
Dim cp As CreateParams = MyBase.CreateParams
If Not aeroEnabled Then
cp.ClassStyle = cp.ClassStyle Or NativeConstants.CS_DROPSHADOW
Return cp
Else
Return cp
End If
End Get
End Property
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case NativeConstants.WM_NCPAINT
Dim val = 2
If aeroEnabled Then
NativeMethods.DwmSetWindowAttribute(Handle, 2, val, 4)
Dim bla As New NativeStructs.MARGINS()
With bla
.bottomHeight = 1
.leftWidth = 1
.rightWidth = 1
.topHeight = 1
End With
NativeMethods.DwmExtendFrameIntoClientArea(Handle, bla)
End If
Exit Select
End Select
MyBase.WndProc(m)
End Sub
Private Sub CheckAeroEnabled()
If Environment.OSVersion.Version.Major >= 6 Then
Dim enabled As Integer = 0
Dim response As Integer = NativeMethods.DwmIsCompositionEnabled(enabled)
aeroEnabled = (enabled = 1)
Else
aeroEnabled = False
End If
End Sub
End Class
Public Class NativeStructs
Public Structure MARGINS
Public leftWidth As Integer
Public rightWidth As Integer
Public topHeight As Integer
Public bottomHeight As Integer
End Structure
End Class
Public Class NativeMethods
_
Public Shared Function DwmExtendFrameIntoClientArea(ByVal hWnd As IntPtr, ByRef pMarInset As NativeStructs.MARGINS) As Integer
End Function
_
Friend Shared Function DwmSetWindowAttribute(ByVal hwnd As IntPtr, ByVal attr As Integer, ByRef attrValue As Integer, ByVal attrSize As Integer) As Integer
End Function
_
Public Shared Function DwmIsCompositionEnabled(ByRef pfEnabled As Integer) As Integer
End Function
End Class
Public Class NativeConstants
Public Const CS_DROPSHADOW As Integer = &H20000
Public Const WM_NCPAINT As Integer = &H85
End Class

Reply

Hi,

Thanks but it's showing me some errors.

Reply

Hi ,

How i Can Change Color Of Shadow ?

Reply

It's not possible because this is a system feature that we are using.

Reply

So , Can U Make Other Themes And Design For Later ;) ?

Reply

Hi Saef,

Can we give this shadow effect to excel userform using VBA
Pls Can you post some code for it .....

Thanks

Reply

It's the same as the one Mohammad Shimran has given.
It just increases the size of code.
Aero is a SH**TY thing.

Reply

Post a Comment

Note: Only a member of this blog may post a comment.