473,416 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Adding a shadow around panel

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
Nov 20 '05 #1
3 14455
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
----------------
"Lasse Eskildsen" <Le****@DELETEwebspeed.dk> wrote in message
news:uV*************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #2
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
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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
----------------
"Lasse Eskildsen" <Le****@DELETEwebspeed.dk> wrote in message
news:uV*************@TK2MSFTNGP11.phx.gbl...
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


Nov 20 '05 #3
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/downl...withshadow.zip

Ken
--------------
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ON*************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Acer | last post by:
hi, what's the best way to display pictures with an automatic generated shadow ?
3
by: Pawel | last post by:
Hi, What is the best way to add a drop shadow around table borders with just html and css that looks nice and works in most browsers? I have written a program for making online web site...
5
by: Jeremy Ames | last post by:
I have run into a major road block with my page development projects. I am trying to add a literal control to my asp.net page and I got an error stating that the control could not be added because...
0
by: juglesh | last post by:
Hello, I've searched and d/l'd but cant seem to find a way of creating a semi-transparent drop shadow for an image. Let me say, be fore I go on, I *do not* want one of those scripts that resizes...
6
by: Brett Romero | last post by:
How can I add design-time support to a custom control in VS.NET 2005? Thanks, Brett
16
by: eholz1 | last post by:
Hello CSS group, I saw a beautiful effect that I would like to use either by CSS or using photoshop to create the image/effect (maybe even imagemagick) the site address is:...
1
by: nondos | last post by:
Hello, 1. Is there anyway to add shadow to panel control like On Windows Vista, each frame window has a cool shadow ? 2. Is there anyway to change panel control with background image...
0
by: wojski696969 | last post by:
Hi.. I'm using ASP.NET AJAX Control Toolkit. I've got collapsible extender (CE) putted inside of modal popup extender (MPE), and there is a problem if i scroll the page when collapsible area is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.