繁体   English   中英

如何在椭圆上绘制阴影?

[英]How to draw a drop shadow on ellipse?

g.FillEllipse(Pens.Black, ClientRectangle.X, ClientRectangle.Y, 60, 60); 这是我的椭圆代码。 因此,我想为其制作透明阴影,并尽可能调整阴影大小。

有一个在没有现成的阴影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);

}

请注意,对于非黑色,您通常会希望使用黑色或灰色或该颜色的深色。

请注意,您的代码无法按发布的方式工作:您只能用笔绘图或用刷子填充!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM