官网

http://www.hzhcontrols.com/

前提

入行已经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

用处及效果

准备工作

之前的瓶子是朝下的,这里扩展一下 朝上

(五十六)c#Winform自定义控件-瓶子(工业)

开始

增加一个属性

        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自定义控件-朝上的瓶子的更多相关文章

  1. (十八)c#Winform自定义控件-提示框

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  2. (四十八)c#Winform自定义控件-下拉按钮

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  3. (七十八)c#Winform自定义控件-倒影组件

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  4. (八)c#Winform自定义控件-分割线

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  5. (二十八)c#Winform自定义控件-文本框(一)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  6. (五十八)c#Winform自定义控件-管道阀门(工业)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  7. (六十八)c#Winform自定义控件-DEMO整理

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  8. (三十八)c#Winform自定义控件-圆形进度条-HZHControls

    官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...

  9. c#Winform自定义控件-目录

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  10. winform 自定义控件(高手)

    高手推荐:https://www.cnblogs.com/bfyx/p/11364884.html   c#Winform自定义控件-目录   前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件 ...

随机推荐

  1. css3新单位vw、vh、vmin、vmax的使用详解

    1,vw.vh.vmin.vmax 的含义 (1) vw. vh. vmin. vmax 是一种视窗单位,也是相对单位.它相对的不是父节点或者页面的根节点.而是由视窗( Viewport)大小来决定的 ...

  2. 力扣560(java&python)-和为k的子数组(中等)

    题目: 给你一个整数数组 nums 和一个整数 k ,请你统计并返回 该数组中和为 k 的连续子数组的个数 . 示例 1: 输入:nums = [1,1,1], k = 2输出:2示例 2: 输入:n ...

  3. 如何使用 Serverless Devs 部署静态网站到函数计算

    ​简介:手把手教你:如何使用 Serverless Devs 部署静态网站到函数计算. 前言 公司经常有一些网站需要发布上线,对比了几款不同的产品后,决定使用阿里云的函数计算(FC)来托管构建出来的静 ...

  4. 深入浅出讲解MSE Nacos 2.0新特性

    简介: 随着云原生时代的到来,微服务已经成为应用架构的主流,Nacos也凭借简单易用.稳定可靠.性能卓越的核心竞争力成为国内微服务领域首选的注册中心和配置中心:Nacos2.0更是把性能做到极致,让业 ...

  5. [Go] 浅谈 Golang struct 与 PHP class 的相似

    Golang 中的 struct 与 PHP 的 class 在使用方式上差不多. struct 中的成员可以类比 class 中的属性,struct 中的成员函数可以类比 class 中的方法. 对 ...

  6. SQL server 树形递归查询

    1,原始查询 原始表格查询: select * from dbo.T_DeptInfo; 原始表格查询结果: 2,递归查询 -- with 一个临时表(括号里包括的是你要查询的列名) with tem ...

  7. 数据表删除DROP TRUNCATE DELETE区别

    总的来说,DROP 用于删除整个数据库对象(表结构和数据全部删除),DELETE 用于删除表中的数据,而 TRUNCATE 也是删除表中的数据,但比 DELETE 更快,且无法指定条件删除.根据需求, ...

  8. Gem离线包安装

    Gem离线包安装 项目环境 以 rest-client 为例 本地如果是rails项目环境: ruby '2.7.0' gem 'rails', '~> 6.0.3', '>= 6.0.3 ...

  9. Linux curl命令使用代理、以及代理种类介绍

    Linux curl命令使用代理.以及代理种类介绍 https://www.cnblogs.com/panxuejun/p/10574038.html 测试代理的方法: curl -x ip:port ...

  10. gin里获取http请求过来的参数

    https://www.bilibili.com/video/av68769981/?p=2 课程代码: https://www.qfgolang.com/?special=ginkuangjia&a ...