ovalshape C# 真正纯WinForm打造指示灯

20190328 雨,又下雨~

这几天无聊,刚好看到别人c++软件有指示灯的控件,想着自己也弄一个练练手,做出来效果还不错,应该可以帮到有需要的人。

效果图如下:

核心代码如下:

这一段是实现带放射效果的圆形图案,纯色的实在难看(手动扶额)。

        private void Ovalshape_Paint(object sender, PaintEventArgs e)
        {
            //重绘时 画出中心放射颜色的圆形
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(0, 0, this.Size.Width, this.Size.Height);
            PathGradientBrush pthGrBrush = new PathGradientBrush(path);
            pthGrBrush.CenterColor = CenterColor;
            Color[] colors = { CurrentColor };
            pthGrBrush.SurroundColors = colors;
            e.Graphics.FillEllipse(pthGrBrush, 0, 0, this.Size.Width, this.Size.Height);
                 
        }

这一段是实现圆形边框,不然正方形边角也还是难看。

        protected override void OnPaint(PaintEventArgs pevent)
        {
            //使控件边界也为圆形
            GraphicsPath graphics = new GraphicsPath();
            graphics.AddEllipse(0, 0, this.Width, this.Height);
            this.Region = new System.Drawing.Region(graphics);
            base.OnPaint(pevent);
            base.OnPaint(pevent);
        }

源码照旧放在马云那儿。(https://gitee.com/newideas/ovalshape

直接要封装好的库文件的在这里:https://download.youkuaiyun.com/download/newidea07/11070057

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值