(八十七)c#Winform自定义控件-朝上的瓶子
官网
前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
如果觉得写的还行,请点个 star 支持一下吧
欢迎前来交流探讨: 企鹅群568015492 
来都来了,点个【推荐】再走吧,谢谢
NuGet
Install-Package HZH_Controls
目录
http://www.hzhcontrols.com/blog-63.html
用处及效果

准备工作
之前的瓶子是朝下的,这里扩展一下 朝上
开始
增加一个属性
private Direction direction = Direction.Down; [Description("瓶子方向,默认朝下"), Category("自定义")] public Direction Direction { get { return direction; } set { direction = value; Refresh(); } } |
重绘里面判断朝上的代码
else { //写文字 var size = g.MeasureString(title, Font); g.DrawString(title, Font, new SolidBrush(ForeColor), new PointF((this.Width - size.Width) / 2, this.Height - size.Height - 2)); //画空瓶子 GraphicsPath pathPS = new GraphicsPath(); Point[] psPS = new Point[] { new Point(m_workingRect.Left + m_workingRect.Width / 4, m_workingRect.Top), new Point(m_workingRect.Right - 1- m_workingRect.Width / 4, m_workingRect.Top), new Point(m_workingRect.Right - 1, m_workingRect.Top + 15), new Point(m_workingRect.Right - 1, m_workingRect.Bottom), new Point(m_workingRect.Left , m_workingRect.Bottom), new Point(m_workingRect.Left, m_workingRect.Top + 15), }; pathPS.AddLines(psPS); pathPS.CloseAllFigures(); g.FillPath(new SolidBrush(bottleColor), pathPS); //画液体 decimal decYTHeight = (m_value / maxValue) * m_workingRect.Height; GraphicsPath pathYT = new GraphicsPath(); Rectangle rectYT = Rectangle.Empty; if (decYTHeight > m_workingRect.Height - 15) { PointF[] psYT = new PointF[] { new PointF((float)(m_workingRect.Left+(decYTHeight-(m_workingRect.Height-15)))+3,(float)(m_workingRect.Bottom-decYTHeight)), new PointF((float)(m_workingRect.Right-(decYTHeight-(m_workingRect.Height-15)))-3,(float)(m_workingRect.Bottom-decYTHeight)), new PointF(m_workingRect.Right-1, m_workingRect.Top+15), new PointF(m_workingRect.Right-1, m_workingRect.Bottom), new PointF(m_workingRect.Left, m_workingRect.Bottom), new PointF(m_workingRect.Left, m_workingRect.Top+15), }; pathYT.AddLines(psYT); pathYT.CloseAllFigures(); rectYT = new Rectangle(m_workingRect.Left + (int)(decYTHeight - (m_workingRect.Height - 15)) +1, (int)(m_workingRect.Bottom - decYTHeight - 4), m_workingRect.Width - (int)(decYTHeight - (m_workingRect.Height - 15)) * 2-2 , 10); } else { PointF[] psYT = new PointF[] { new PointF(m_workingRect.Left,(float)(m_workingRect.Bottom-decYTHeight)), new PointF(m_workingRect.Right-1,(float)(m_workingRect.Bottom-decYTHeight)), new PointF(m_workingRect.Right-1,m_workingRect.Bottom), new PointF(m_workingRect.Left,m_workingRect.Bottom), }; pathYT.AddLines(psYT); pathYT.CloseAllFigures(); rectYT = new Rectangle(m_workingRect.Left, m_workingRect.Bottom - (int)decYTHeight - 5, m_workingRect.Width, 10); } g.FillPath(new SolidBrush(liquidColor), pathYT); g.FillPath(new SolidBrush(Color.FromArgb(50, bottleMouthColor)), pathYT); //画液体面 g.FillEllipse(new SolidBrush(liquidColor), rectYT); g.FillEllipse(new SolidBrush(Color.FromArgb(50, Color.White)), rectYT); //画高亮 int intCount = m_workingRect.Width / 2 / 4; int intSplit = (255 - 100) / intCount; for (int i = 0; i < intCount; i++) { int _penWidth = m_workingRect.Width / 2 - 4 * i; if (_penWidth <= 0) _penWidth = 1; g.DrawLine(new Pen(new SolidBrush(Color.FromArgb(10, Color.White)), _penWidth), new Point(m_workingRect.Width / 2, m_workingRect.Top + 15), new Point(m_workingRect.Width / 2, m_workingRect.Bottom)); if (_penWidth == 1) break; } //画瓶底 g.FillEllipse(new SolidBrush(liquidColor), new RectangleF(m_workingRect.Left, m_workingRect.Bottom - 5, m_workingRect.Width - 2, 10)); g.FillEllipse(new SolidBrush(Color.FromArgb(50, liquidColor)), new RectangleF(m_workingRect.Left, m_workingRect.Bottom - 5, m_workingRect.Width - 2, 10)); //画瓶口 g.FillRectangle(new SolidBrush(bottleMouthColor), new Rectangle(m_workingRect.Left + m_workingRect.Width / 4, m_workingRect.Top - 15 + 1, m_workingRect.Width / 2, 15)); //画瓶颈阴影 GraphicsPath pathPJ = new GraphicsPath(); Point[] psPJ = new Point[] { new Point(m_workingRect.Left+m_workingRect.Width/4, m_workingRect.Top), new Point(m_workingRect.Right-1-m_workingRect.Width/4, m_workingRect.Top), new Point(m_workingRect.Right-1, m_workingRect.Top+15), new Point(m_workingRect.Left, m_workingRect.Top+15) }; pathPJ.AddLines(psPJ); pathPJ.CloseAllFigures(); g.FillPath(new SolidBrush(Color.FromArgb(50, bottleMouthColor)), pathPJ); //写编号 if (!string.IsNullOrEmpty(m_NO)) { var nosize = g.MeasureString(m_NO, Font); g.DrawString(m_NO, Font, new SolidBrush(ForeColor), new PointF((this.Width - nosize.Width) / 2, m_workingRect.Bottom - nosize.Height - 10)); } } |
最后的话
如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧
(八十七)c#Winform自定义控件-朝上的瓶子的更多相关文章
- (十八)c#Winform自定义控件-提示框
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (四十八)c#Winform自定义控件-下拉按钮
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- (七十八)c#Winform自定义控件-倒影组件
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- (八)c#Winform自定义控件-分割线
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (二十八)c#Winform自定义控件-文本框(一)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (五十八)c#Winform自定义控件-管道阀门(工业)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- (六十八)c#Winform自定义控件-DEMO整理
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- (三十八)c#Winform自定义控件-圆形进度条-HZHControls
官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...
- c#Winform自定义控件-目录
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- winform 自定义控件(高手)
高手推荐:https://www.cnblogs.com/bfyx/p/11364884.html c#Winform自定义控件-目录 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件 ...
随机推荐
- 详细的讲一下微服务框架--SpringCloud
一:微服务架构? 1.为什么需要微服务架构 大家都知道,最开始开发系统就是单机模式(only one computer).但是随着网络的不断发展,数据不断的增加,业务不断的增加,之前在一台机器上实现的 ...
- 轻松复现一张AI图片
轻松复现一张AI图片 现在有一个非常漂亮的AI图片,你是不是想知道他是怎么生成的? 今天我会交给大家三种方法,学会了,什么图都可以手到擒来了. 需要的软件 在本教程中,我们将使用AUTOMATIC11 ...
- Résumé Review 二分方法题解
一道非常好的数学题,不愧是CF的题,跟某些网站上的水题.恶心题没法比~ 题意 这里就要夸一下某谷了,翻译的很好,不像我,在CF上用deepl翻译,不够清晰(←全是废话) 分析 先不考虑 bi ,考虑转 ...
- C#的基于.net framework的Dll模块编程(二) - 编程手把手系列文章
今天继续这个系列博文的编写.接上次的篇幅,这次介绍关于C#的Dll类库的创建的内容.因为是手把手系列,所以对于需要入门的朋友来说还是挺好的,下面开始咯: 一.新建Dll类库: 这里直接创建例子的Dll ...
- 《领域驱动设计》:从领域视角深入仓储(Repository)的设计和实现
简介: <领域驱动设计>中的Repository(下面将用仓储表示)层实际上是极具有挑战性的,对于它的理解,也十分重要.本文讲大部分内容都在众多前辈理论基础上,从一个崭新的领域视觉开始探索 ...
- 揭秘远程证明架构EAA:机密容器安全部署的最后一环 | 龙蜥技术
简介:如果需要在云上 HW-TEE 环境里启动一个加密容器,如何在启动过程中获取容器的解密密钥? 文 / 周亮, 云原生机密计算 SIG 核心成员. 在云原生场景下,基于HW-TEE(如Inte ...
- [FAQ] IDE: Goland 注释符后面添加空行
如图所示,Code Style 对应语言 Go 勾选上注释空行的选项. Refer:Goland官网 Goland下载 Link:https://www.cnblogs.com/farwish/p/1 ...
- [FAQ] VisualStudio, Source file requires different compiler version (current compiler is 0.6.1+cxxxxxx)
当使用的 Solidity 库文件中 pragma 指定的 版本 与本地编译器的使用版本不一致时,会出现这类提示. 解决方式是菜单栏 View -> Extensions -> Exten ...
- Quill富文本编辑器的实践 - DevUI
DevUI 是一款面向企业中后台产品的开源前端解决方案,它倡导沉浸.灵活.至简的设计价值观,提倡设计者为真实的需求服务,为多数人的设计,拒绝哗众取宠.取悦眼球的设计.如果你正在开发 ToB 的工具类产 ...
- ASP.NET CORE 发布时不编译Views文件夹
.net core 3.0正式版已经发布,目前整体相对来说已经稳定了,可以进行生产开发. 发布时默认情况下Views是直接编译成DLL文件(XXXXXX.Views.dll),日常开发维护过程中,经常 ...