Found the following interesting discussion in the Newsgroups:
Adding a shadow around panel by:Lasse Eskildsen | |
Hi, I have a panel on my form, and I would like to add a shadow around that panel, just like Xp as around the menus etc. I tried drawing it with the lineargradientbrush, but it doesn't look very nice. So my question is: How can I make a nice shadow effect on a panel? Thanks for your time :) -- Lasse | |
Reply: by:Ken Tucker [MVP] | |
Hi, Is this what you are looking for? Public Class ShadowPanel Inherits Panel Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As IntPtr) _ As IntPtr Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As IntPtr, _ ByVal hdc As IntPtr) As Integer Public Sub New() Me.BorderStyle = BorderStyle.Fixed3D End Sub Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Const WM_NCPAINT = &H85 If m.Msg = WM_NCPAINT Then Dim hdc As IntPtr = GetWindowDC(m.HWnd) Dim g As Graphics = Graphics.FromHdc(hdc) Dim rDraw As Rectangle = New Rectangle(0, 0, Me.Width - 1, Me.Height - 1) Dim pBottom As Pen = New Pen(Color.Gray, 2) Dim pTop As Pen = New Pen(Color.White, 2) g.DrawRectangle(pBottom, rDraw) Dim pts(2) As Point pts(0) = New Point(0, Me.Height - 1) pts(1) = New Point(0, 0) pts(2) = New Point(Me.Width - 1, 0) g.DrawLines(pTop, pts) ReleaseDC(Me.Handle, hdc) Else MyBase.WndProc(m) End If End Sub End Class Ken | |
Reply: by:Brian Henry | |
Hi Ken, I don't think thats what he means, more like a alpha channel shadow that you get in windows 2000/XP behind menus | |
Reply: by:Ken Tucker [MVP] | |
Hi, Here is a sample I made. I believe this is what he wants. I used the class in my last message and added to the form in windows forms generated code section. In the paint event I draw the shadow. http://www.onteorasoftware.com/downloads/panelwithshadow.zip Ken |