【发布时间】:2015-03-23 19:04:41
【问题描述】:
g.FillEllipse(Pens.Black, ClientRectangle.X, ClientRectangle.Y, 60, 60);
这是我的椭圆代码。
所以我想为它制作透明的阴影,如果可能的话,可以调整阴影的大小。
【问题讨论】:
标签: c# winforms drawing shadow
g.FillEllipse(Pens.Black, ClientRectangle.X, ClientRectangle.Y, 60, 60);
这是我的椭圆代码。
所以我想为它制作透明的阴影,如果可能的话,可以调整阴影的大小。
【问题讨论】:
标签: c# winforms drawing shadow
winforms 中没有现成的阴影,但是你可以在绘制真实的椭圆之前先画几个半透明的椭圆,得到一个不错的效果:
不要让代码欺骗你:阴影实际上只由三行创建。
private void panel1_Paint_1(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
Color color = Color.Blue;
Color shadow = Color.FromArgb(255, 16, 16, 16);
for (int i = 0; i < 8; i++ )
using (SolidBrush brush = new SolidBrush(Color.FromArgb(80 - i * 10, shadow)))
{ g.FillEllipse(brush, panel1.ClientRectangle.X + i*2,
panel1.ClientRectangle.Y + i, 60, 60); }
using (SolidBrush brush = new SolidBrush(color))
g.FillEllipse(brush, panel1.ClientRectangle.X, panel1.ClientRectangle.Y, 60, 60);
// move to the right to use the same coordinates again for the drawn shape
g.TranslateTransform(80, 0);
for (int i = 0; i < 8; i++ )
using (Pen pen = new Pen(Color.FromArgb(80 - i * 10, shadow), 2.5f))
{ g.DrawEllipse(pen, panel1.ClientRectangle.X + i * 1.25f,
panel1.ClientRectangle.Y + i, 60, 60); }
using (Pen pen = new Pen(color))
g.DrawEllipse(pen, panel1.ClientRectangle.X, panel1.ClientRectangle.Y, 60, 60);
}
请注意,对于非黑色颜色,您通常希望使用黑色或灰色或该颜色的非常暗的色调..
请注意,您的代码不像发布的那样工作:您只能用钢笔绘图或用画笔填充!
【讨论】:
Pen mypen = new Pen(color, 3); SolidBrush mybrush = new SolidBrush(color); //after drawing the ellipse // drawCircle(e.Graphics, mypen, this.center_x, this.center_y, this.radii); //you need to fill it double radius = this.radii / 1.8; fillCircle(e.Graphics, mybrush, this.center_x, this.center_y,(float) radius);