首先我们学习组件的开发,必须要了解winform的绘图是怎么绘制的,
以下知识建议先自行了解:
PaintEventArgs
Rectangle
GraphicsPath
软谋的.NET全套架构视频,大多视频包含源码,录制时间(初中级是2019~2020高级架构是2020~2021),原价6499,现仅需299元。这个活动周三推出后,受到热捧,仅一个技术群就几十人抢购!最后几天活动,目录和介绍:点击下方超链接查看 需要的加微zls20210502,进技术群的加微mm1552923,备注进群 |
我们使用GraphicsPath添加一个三角形路径
GraphicsPath graphicsPath = new GraphicsPath();
graphicsPath.AddLine(new Point(0, 0), new Point(0, 50));
graphicsPath.AddLine(new Point(0, 0), new Point(50, 0));
graphicsPath.AddLine(new Point(0, 50), new Point(50, 0));
graphicsPath.AddLine(new Point(50, 0), new Point(0, 50));
graphicsPath.CloseFigure();
然后把三角形绘制出来
//绘制三角形
e.Graphics.FillPath(new SolidBrush(Color.FromArgb(15, 93, 244)), graphicsPath);
然后我们添加分割线
//绘制下划线
e.Graphics.DrawLine(new Pen(Color.FromArgb(15, 93, 244)), new Point(0, 50), new Point(this.Width, 50));
接着绘制序号
//绘制序号
e.Graphics.DrawString(_sortNo.ToString().PadLeft(3,'0'), font, new SolidBrush(Color.White), new Point(0, 0));
床位一共有两种模式:
1:未使用空床情况
2:已使用情况
当未使用时 绘制空床
e.Graphics.DrawString("空床", font, new SolidBrush(Color.FromArgb(14, 43, 94)), new Point(this.Width / 2 - 24, this.Height / 2 - 12));
当已使用时绘制用户信息及其临床诊断以及护理类别
//绘制类别
font = new Font("微软雅黑", 12, FontStyle.Bold);
e.Graphics.DrawString(_UserType, font, new SolidBrush(Color.FromArgb(14, 43, 94)), new Point(this.Width / 2 - 12, 13));
//绘制用户姓名
font = new Font("微软雅黑", 24, FontStyle.Bold);
e.Graphics.DrawString(_UserName, font, new SolidBrush(Color.FromArgb(14, 43, 94)), new Point(55, 63));
总结
本篇博客描述了c#Winform自定义控件GDI+实现住院病床控件
如果觉得还不错,请给个关注