Adding a shadow around panel

 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值