+ 1
Shadows on WinForm c#
hello everyone, i wanna ask how can i apply a nice shadow effect on my WindowsForm .net project ?! i saw some codes on StackOverFlow But they only work on windows10 and they only two sides shadow , i want to have a FULL 4 sides shadow , (i mean shadow on 4 corners not only 2) and thanks !
1 Answer
+ 1
Create a new class that inherits from Form:
public class ShadowedForm : Form
{
// ...
}
Override the CreateParams property to add the WS_EX_COMPOSITED and CS_DROPSHADOW styles:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
cp.ClassStyle |= 0x00020000; // CS_DROPSHADOW
return cp;
}
}
Override the OnPaint method to draw the shadow:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using (var shadowBrush = new SolidBrush(Color.FromArgb(30, 0, 0, 0))) { var shadowSize = 10; var shadowRect = new Rectangle(-shadowSize, -shadowSize, Width + shadowSize, Height + shadowSize); e.Graphics.FillRectangle(shadowBrush, shadowRect); } }
Then use
Application.Run(new ShadowForm())