Found the following interesting discussion in the Newsgroups:
Adding a shadow around panelby:Lasse Eskildsen Hi,I have a panel on my form, and I would like to add a shadow around thatpanel, just like Xp as around the menus etc.I tried drawing it with the lineargradientbrush, but it doesn't look verynice.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 ShadowPanelInherits PanelDeclare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As IntPtr) _As IntPtrDeclare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As IntPtr, _ByVal hdc As IntPtr) As IntegerPublic Sub New()Me.BorderStyle = BorderStyle.Fixed3DEnd SubProtected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)Const WM_NCPAINT = &H85If m.Msg = WM_NCPAINT ThenDim 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 Pointpts(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)ElseMyBase.WndProc(m)End IfEnd SubEnd ClassKen Reply:by:Brian Henry Hi Ken,I don't think thats what he means, more like a alpha channel shadow that youget 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.zipKen
转载请注明原文地址: https://ibbs.8miu.com/read-8915.html