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