精华内容
下载资源
问答
  • 2021-05-06 16:03:41

    参考网址:C# 开源仪表盘库—Agauge App

    主要引用了AGauge.dll,在此基础上做了些修改,运行如下

    代码下载地址。 

    更多相关内容
  • 仪表盘控件,可以加载到winform中。也适合新手学习。
  • 通过自定义控件,编程实现的仪表盘形状的控件,可以加到Winform程序里做动态显示数据,美化界面。使用方便简单。
  • c# winform仪表盘

    热门讨论 2012-12-07 09:35:19
    不知道从哪找的一个gdi画的仪表盘,感觉还可以
  • winform 仪表盘,非原创

    2018-05-23 15:43:39
    winform 仪表盘,我不是程序员,请叫我代码搬运工 。
  • 主要介绍了c#Winform自定义控件-仪表盘功能,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
  • C# Winform 仪表盘

    2018-07-14 17:42:00
    winform仪表盘相关下载链接://download.csdn.net/download/floweroflvoe/10432601?utm_source=bbsseo 控件首次拖拽上来是这样的: Demo中美化之后是这样的: 这是修改demo后的成果:   其中颜色是一点...

    winform 仪表盘相关下载链接://download.csdn.net/download/floweroflvoe/10432601?utm_source=bbsseo

     

     

    控件首次拖拽上来是这样的:        Demo中美化之后是这样的:      这是修改demo后的成果:

            

    其中颜色是一点一点配出来的,线条与色块是一个一个Range调整大小与位置得到的,最后的指针颜色本是没有和谐的颜色,通过修改源代码添加了合适的颜色。

    样式是通过属性编辑器添加修改的,最后生成的设计器具体代码如下:

    // 
                // aGauge1
                // 
                this.aGauge1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(16)))), ((int)(((byte)(24)))), ((int)(((byte)(57)))));
                this.aGauge1.BaseArcColor = System.Drawing.Color.FromArgb(((int)(((byte)(147)))), ((int)(((byte)(202)))), ((int)(((byte)(250)))));
                this.aGauge1.BaseArcRadius = 82;
                this.aGauge1.BaseArcStart = 155;
                this.aGauge1.BaseArcSweep = 230;
                this.aGauge1.BaseArcWidth = 2;
                this.aGauge1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.aGauge1.GaugeAutoSize = true;
                aGaugeLabel1.Color = System.Drawing.Color.White;
                aGaugeLabel1.Font = new System.Drawing.Font("Verdana", 9.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                aGaugeLabel1.Name = "GaugeLabel1";
                aGaugeLabel1.Position = new System.Drawing.Point(200, 260);
                aGaugeLabel1.Text = "0";
                this.aGauge1.GaugeLabels.Add(aGaugeLabel1);
                aGaugeRange1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(129)))), ((int)(((byte)(133)))), ((int)(((byte)(204)))));
                aGaugeRange1.EndValue = 6.8F;
                aGaugeRange1.InnerRadius = 90;
                aGaugeRange1.InRange = false;
                aGaugeRange1.Name = "ShortRange";
                aGaugeRange1.OuterRadius = 91;
                aGaugeRange1.StartValue = 1.8F;
                aGaugeRange2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(133)))), ((int)(((byte)(112)))), ((int)(((byte)(227)))));
                aGaugeRange2.EndValue = 1.7F;
                aGaugeRange2.InnerRadius = 70;
                aGaugeRange2.InRange = false;
                aGaugeRange2.Name = "GaugeRange3";
                aGaugeRange2.OuterRadius = 77;
                aGaugeRange2.StartValue = 1.2F;
                aGaugeRange3.Color = System.Drawing.Color.FromArgb(((int)(((byte)(132)))), ((int)(((byte)(101)))), ((int)(((byte)(225)))));
                aGaugeRange3.EndValue = 1F;
                aGaugeRange3.InnerRadius = 70;
                aGaugeRange3.InRange = false;
                aGaugeRange3.Name = "GaugeRange2";
                aGaugeRange3.OuterRadius = 77;
                aGaugeRange3.StartValue = 0.5F;
                aGaugeRange4.Color = System.Drawing.Color.FromArgb(((int)(((byte)(131)))), ((int)(((byte)(94)))), ((int)(((byte)(223)))));
                aGaugeRange4.EndValue = 0.3F;
                aGaugeRange4.InnerRadius = 70;
                aGaugeRange4.InRange = false;
                aGaugeRange4.Name = "GaugeRange1";
                aGaugeRange4.OuterRadius = 77;
                aGaugeRange4.StartValue = -0.2F;
                aGaugeRange5.Color = System.Drawing.Color.FromArgb(((int)(((byte)(134)))), ((int)(((byte)(123)))), ((int)(((byte)(230)))));
                aGaugeRange5.EndValue = 2.4F;
                aGaugeRange5.InnerRadius = 70;
                aGaugeRange5.InRange = false;
                aGaugeRange5.Name = "GaugeRange4";
                aGaugeRange5.OuterRadius = 77;
                aGaugeRange5.StartValue = 1.9F;
                aGaugeRange6.Color = System.Drawing.Color.FromArgb(((int)(((byte)(135)))), ((int)(((byte)(133)))), ((int)(((byte)(231)))));
                aGaugeRange6.EndValue = 3.1F;
                aGaugeRange6.InnerRadius = 70;
                aGaugeRange6.InRange = false;
                aGaugeRange6.Name = "GaugeRange5";
                aGaugeRange6.OuterRadius = 77;
                aGaugeRange6.StartValue = 2.6F;
                aGaugeRange7.Color = System.Drawing.Color.FromArgb(((int)(((byte)(138)))), ((int)(((byte)(153)))), ((int)(((byte)(236)))));
                aGaugeRange7.EndValue = 3.8F;
                aGaugeRange7.InnerRadius = 70;
                aGaugeRange7.InRange = false;
                aGaugeRange7.Name = "GaugeRange6";
                aGaugeRange7.OuterRadius = 77;
                aGaugeRange7.StartValue = 3.3F;
                aGaugeRange8.Color = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(177)))), ((int)(((byte)(239)))));
                aGaugeRange8.EndValue = 4.5F;
                aGaugeRange8.InnerRadius = 70;
                aGaugeRange8.InRange = false;
                aGaugeRange8.Name = "GaugeRange7";
                aGaugeRange8.OuterRadius = 77;
                aGaugeRange8.StartValue = 4F;
                aGaugeRange9.Color = System.Drawing.Color.FromArgb(((int)(((byte)(142)))), ((int)(((byte)(194)))), ((int)(((byte)(244)))));
                aGaugeRange9.EndValue = 5.2F;
                aGaugeRange9.InnerRadius = 70;
                aGaugeRange9.InRange = false;
                aGaugeRange9.Name = "GaugeRange8";
                aGaugeRange9.OuterRadius = 77;
                aGaugeRange9.StartValue = 4.7F;
                aGaugeRange10.Color = System.Drawing.Color.FromArgb(((int)(((byte)(143)))), ((int)(((byte)(204)))), ((int)(((byte)(246)))));
                aGaugeRange10.EndValue = 5.9F;
                aGaugeRange10.InnerRadius = 70;
                aGaugeRange10.InRange = false;
                aGaugeRange10.Name = "GaugeRange9";
                aGaugeRange10.OuterRadius = 77;
                aGaugeRange10.StartValue = 5.4F;
                aGaugeRange11.Color = System.Drawing.Color.FromArgb(((int)(((byte)(144)))), ((int)(((byte)(211)))), ((int)(((byte)(247)))));
                aGaugeRange11.EndValue = 6.6F;
                aGaugeRange11.InnerRadius = 70;
                aGaugeRange11.InRange = false;
                aGaugeRange11.Name = "GaugeRange10";
                aGaugeRange11.OuterRadius = 77;
                aGaugeRange11.StartValue = 6.1F;
                aGaugeRange12.Color = System.Drawing.Color.FromArgb(((int)(((byte)(144)))), ((int)(((byte)(214)))), ((int)(((byte)(248)))));
                aGaugeRange12.EndValue = 7.3F;
                aGaugeRange12.InnerRadius = 70;
                aGaugeRange12.InRange = false;
                aGaugeRange12.Name = "GaugeRange11";
                aGaugeRange12.OuterRadius = 77;
                aGaugeRange12.StartValue = 6.8F;
                aGaugeRange13.Color = System.Drawing.Color.FromArgb(((int)(((byte)(144)))), ((int)(((byte)(212)))), ((int)(((byte)(247)))));
                aGaugeRange13.EndValue = 8F;
                aGaugeRange13.InnerRadius = 70;
                aGaugeRange13.InRange = false;
                aGaugeRange13.Name = "GaugeRange12";
                aGaugeRange13.OuterRadius = 77;
                aGaugeRange13.StartValue = 7.5F;
                aGaugeRange14.Color = System.Drawing.Color.FromArgb(((int)(((byte)(142)))), ((int)(((byte)(210)))), ((int)(((byte)(247)))));
                aGaugeRange14.EndValue = 8.7F;
                aGaugeRange14.InnerRadius = 70;
                aGaugeRange14.InRange = false;
                aGaugeRange14.Name = "GaugeRange13";
                aGaugeRange14.OuterRadius = 77;
                aGaugeRange14.StartValue = 8.2F;
                aGaugeRange15.Color = System.Drawing.Color.FromArgb(((int)(((byte)(143)))), ((int)(((byte)(203)))), ((int)(((byte)(246)))));
                aGaugeRange15.EndValue = 9.4F;
                aGaugeRange15.InnerRadius = 70;
                aGaugeRange15.InRange = false;
                aGaugeRange15.Name = "GaugeRange14";
                aGaugeRange15.OuterRadius = 77;
                aGaugeRange15.StartValue = 8.9F;
                aGaugeRange16.Color = System.Drawing.Color.FromArgb(((int)(((byte)(141)))), ((int)(((byte)(190)))), ((int)(((byte)(243)))));
                aGaugeRange16.EndValue = 10.1F;
                aGaugeRange16.InnerRadius = 70;
                aGaugeRange16.InRange = false;
                aGaugeRange16.Name = "GaugeRange15";
                aGaugeRange16.OuterRadius = 77;
                aGaugeRange16.StartValue = 9.6F;
                aGaugeRange17.Color = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(172)))), ((int)(((byte)(238)))));
                aGaugeRange17.EndValue = 10.8F;
                aGaugeRange17.InnerRadius = 70;
                aGaugeRange17.InRange = false;
                aGaugeRange17.Name = "GaugeRange16";
                aGaugeRange17.OuterRadius = 77;
                aGaugeRange17.StartValue = 10.3F;
                aGaugeRange18.Color = System.Drawing.Color.FromArgb(((int)(((byte)(137)))), ((int)(((byte)(151)))), ((int)(((byte)(235)))));
                aGaugeRange18.EndValue = 11.5F;
                aGaugeRange18.InnerRadius = 70;
                aGaugeRange18.InRange = false;
                aGaugeRange18.Name = "GaugeRange17";
                aGaugeRange18.OuterRadius = 77;
                aGaugeRange18.StartValue = 11F;
                aGaugeRange19.Color = System.Drawing.Color.FromArgb(((int)(((byte)(135)))), ((int)(((byte)(133)))), ((int)(((byte)(231)))));
                aGaugeRange19.EndValue = 12.2F;
                aGaugeRange19.InnerRadius = 70;
                aGaugeRange19.InRange = false;
                aGaugeRange19.Name = "GaugeRange18";
                aGaugeRange19.OuterRadius = 77;
                aGaugeRange19.StartValue = 11.7F;
                aGaugeRange20.Color = System.Drawing.Color.FromArgb(((int)(((byte)(134)))), ((int)(((byte)(123)))), ((int)(((byte)(230)))));
                aGaugeRange20.EndValue = 12.9F;
                aGaugeRange20.InnerRadius = 70;
                aGaugeRange20.InRange = false;
                aGaugeRange20.Name = "GaugeRange19";
                aGaugeRange20.OuterRadius = 77;
                aGaugeRange20.StartValue = 12.4F;
                aGaugeRange21.Color = System.Drawing.Color.FromArgb(((int)(((byte)(133)))), ((int)(((byte)(111)))), ((int)(((byte)(227)))));
                aGaugeRange21.EndValue = 13.6F;
                aGaugeRange21.InnerRadius = 70;
                aGaugeRange21.InRange = false;
                aGaugeRange21.Name = "GaugeRange20";
                aGaugeRange21.OuterRadius = 77;
                aGaugeRange21.StartValue = 13.1F;
                aGaugeRange22.Color = System.Drawing.Color.FromArgb(((int)(((byte)(132)))), ((int)(((byte)(102)))), ((int)(((byte)(225)))));
                aGaugeRange22.EndValue = 14.3F;
                aGaugeRange22.InnerRadius = 70;
                aGaugeRange22.InRange = false;
                aGaugeRange22.Name = "GaugeRange21";
                aGaugeRange22.OuterRadius = 77;
                aGaugeRange22.StartValue = 13.8F;
                aGaugeRange23.Color = System.Drawing.Color.FromArgb(((int)(((byte)(131)))), ((int)(((byte)(93)))), ((int)(((byte)(223)))));
                aGaugeRange23.EndValue = 15F;
                aGaugeRange23.InnerRadius = 70;
                aGaugeRange23.InRange = false;
                aGaugeRange23.Name = "GaugeRange22";
                aGaugeRange23.OuterRadius = 77;
                aGaugeRange23.StartValue = 14.5F;
                aGaugeRange24.Color = System.Drawing.Color.FromArgb(((int)(((byte)(78)))), ((int)(((byte)(115)))), ((int)(((byte)(153)))));
                aGaugeRange24.EndValue = 15.5F;
                aGaugeRange24.InnerRadius = 65;
                aGaugeRange24.InRange = false;
                aGaugeRange24.Name = "SingleGaugeRange";
                aGaugeRange24.OuterRadius = 66;
                aGaugeRange24.StartValue = -0.5F;
                this.aGauge1.GaugeRanges.Add(aGaugeRange1);
                this.aGauge1.GaugeRanges.Add(aGaugeRange2);
                this.aGauge1.GaugeRanges.Add(aGaugeRange3);
                this.aGauge1.GaugeRanges.Add(aGaugeRange4);
                this.aGauge1.GaugeRanges.Add(aGaugeRange5);
                this.aGauge1.GaugeRanges.Add(aGaugeRange6);
                this.aGauge1.GaugeRanges.Add(aGaugeRange7);
                this.aGauge1.GaugeRanges.Add(aGaugeRange8);
                this.aGauge1.GaugeRanges.Add(aGaugeRange9);
                this.aGauge1.GaugeRanges.Add(aGaugeRange10);
                this.aGauge1.GaugeRanges.Add(aGaugeRange11);
                this.aGauge1.GaugeRanges.Add(aGaugeRange12);
                this.aGauge1.GaugeRanges.Add(aGaugeRange13);
                this.aGauge1.GaugeRanges.Add(aGaugeRange14);
                this.aGauge1.GaugeRanges.Add(aGaugeRange15);
                this.aGauge1.GaugeRanges.Add(aGaugeRange16);
                this.aGauge1.GaugeRanges.Add(aGaugeRange17);
                this.aGauge1.GaugeRanges.Add(aGaugeRange18);
                this.aGauge1.GaugeRanges.Add(aGaugeRange19);
                this.aGauge1.GaugeRanges.Add(aGaugeRange20);
                this.aGauge1.GaugeRanges.Add(aGaugeRange21);
                this.aGauge1.GaugeRanges.Add(aGaugeRange22);
                this.aGauge1.GaugeRanges.Add(aGaugeRange23);
                this.aGauge1.GaugeRanges.Add(aGaugeRange24);
                this.aGauge1.Location = new System.Drawing.Point(53, 3);
                this.aGauge1.MaxValue = 16F;
                this.aGauge1.MinValue = -1F;
                this.aGauge1.Name = "aGauge1";
                this.aGauge1.NeedleColor1 = System.Windows.Forms.AGaugeNeedleColor.MyColor;
                this.aGauge1.NeedleColor2 = System.Drawing.Color.Lavender;
                this.aGauge1.NeedleRadius = 35;
                this.aGauge1.NeedleType = System.Windows.Forms.NeedleType.Advance;
                this.aGauge1.NeedleWidth = 2;
                this.aGauge1.ScaleLinesInterColor = System.Drawing.Color.Transparent;
                this.aGauge1.ScaleLinesInterInnerRadius = 61;
                this.aGauge1.ScaleLinesInterOuterRadius = 63;
                this.aGauge1.ScaleLinesInterWidth = 5;
                this.aGauge1.ScaleLinesMajorColor = System.Drawing.Color.FromArgb(((int)(((byte)(118)))), ((int)(((byte)(177)))), ((int)(((byte)(201)))));
                this.aGauge1.ScaleLinesMajorInnerRadius = 54;
                this.aGauge1.ScaleLinesMajorOuterRadius = 57;
                this.aGauge1.ScaleLinesMajorStepValue = 1F;
                this.aGauge1.ScaleLinesMajorWidth = 1;
                this.aGauge1.ScaleLinesMinorColor = System.Drawing.Color.FromArgb(((int)(((byte)(118)))), ((int)(((byte)(177)))), ((int)(((byte)(201)))));
                this.aGauge1.ScaleLinesMinorInnerRadius = 61;
                this.aGauge1.ScaleLinesMinorOuterRadius = 62;
                this.aGauge1.ScaleLinesMinorTicks = 2;
                this.aGauge1.ScaleLinesMinorWidth = 1;
                this.aGauge1.ScaleNumbersColor = System.Drawing.Color.FromArgb(((int)(((byte)(119)))), ((int)(((byte)(177)))), ((int)(((byte)(206)))));
                this.aGauge1.ScaleNumbersFormat = null;
                this.aGauge1.ScaleNumbersRadius = 48;
                this.aGauge1.ScaleNumbersRotation = 0;
                this.aGauge1.ScaleNumbersStartScaleLine = 1;
                this.aGauge1.ScaleNumbersStepScaleLines = 2;
                this.aGauge1.Size = new System.Drawing.Size(554, 338);
                this.aGauge1.TabIndex = 0;
                this.aGauge1.Text = "aGauge1";
                this.aGauge1.Value = 0F;
                this.aGauge1.ValueChanged += new System.EventHandler(this.aGauge1_ValueChanged);
                this.aGauge1.ValueInRangeChanged += new System.EventHandler<System.Windows.Forms.ValueInRangeChangedEventArgs>(this.aGauge1_ValueInRangeChanged);
    System.Windows.Forms.AGaugeLabel aGaugeLabel1 = new System.Windows.Forms.AGaugeLabel();
                System.Windows.Forms.AGaugeRange aGaugeRange1 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange2 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange3 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange4 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange5 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange6 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange7 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange8 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange9 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange10 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange11 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange12 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange13 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange14 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange15 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange16 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange17 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange18 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange19 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange20 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange21 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange22 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange23 = new System.Windows.Forms.AGaugeRange();
                System.Windows.Forms.AGaugeRange aGaugeRange24 = new System.Windows.Forms.AGaugeRange();
    private System.Windows.Forms.AGauge aGauge1;

    关于修改的指针颜色代码:AGauge.cs中修改AGaugeNeedleColor

    public enum AGaugeNeedleColor
    {
    Gray = 0,
    Red = 1,
    Green = 2,
    Blue = 3,
    Yellow = 4,
    Violet = 5,
    Magenta = 6,
    MyColor=7 //新添加的颜色
    };
     switch (m_NeedleColor1)
              {
                  case AGaugeNeedleColor.MyColor:  // 新添加的颜色设置
                                clr1 = Color.FromArgb(114 + subcol, 76 + subcol, 130 + subcol);
                                clr2 = Color.FromArgb(214 - subcol, 176 - subcol, 231 - subcol);
                                clr3 = Color.FromArgb(114 + subcol2, 76 + subcol2, 130 + subcol2);
                                clr4 = Color.FromArgb(214 - subcol2, 176 - subcol2, 231 - subcol2);
                                e.Graphics.DrawEllipse(Pens.BlueViolet, center.X - needleWidth * 3, center.Y - needleWidth * 3, needleWidth * 6, needleWidth * 6);
                  break;
                  case AGaugeNeedleColor.Gray:
                  clr1 = Color.FromArgb(80 + subcol, 80 + subcol, 80 + subcol);
                  clr2 = Color.FromArgb(180 - subcol, 180 - subcol, 180 - subcol);
                  clr3 = Color.FromArgb(80 + subcol2, 80 + subcol2, 80 + subcol2);
                  clr4 = Color.FromArgb(180 - subcol2, 180 - subcol2, 180 - subcol2);
                  e.Graphics.DrawEllipse(Pens.Gray, center.X - needleWidth * 3, center.Y - needleWidth * 3, needleWidth * 6, needleWidth * 6);
                  break;
    }

    重新加载之后属性中就会出现自己新加的颜色:

     

    转载于:https://www.cnblogs.com/Betty-IT/p/9310355.html

    展开全文
  • 用 C# 编写的高性能、易于使用的 .NET WinForm Gauge。 轻松在明暗模式之间切换。 .NET 程序集和示例应用程序。 了解更多信息:http://winformgauge.codearteng.com
  • 自写的一个Winform控件 一个半圆仪表盘 可以应用在一些报表当中 应该还有BUG
  • 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有...码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git 如果觉得写的还行,请点个 star 支持一下吧 欢迎前来交流探讨: 企鹅群5...

    前提

    入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。

    GitHub:https://github.com/kwwwvagaa/NetWinformControl

    码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

    如果觉得写的还行,请点个 star 支持一下吧

    欢迎前来交流探讨: 企鹅群568015492 企鹅群568015492

    麻烦博客下方点个【推荐】,谢谢

    NuGet

    Install-Package HZH_Controls

    目录

    https://blog.csdn.net/kwwwvagaa/article/details/100586547

    用处及效果

    准备工作

    依然使用GDI+画的,不懂的话就百度一下吧

    另外主要用到了三角函数,如果不懂,可以向初中的数学老师再问问(你也可以百度一下)

    开始

    添加一个类UCMeter 继承 UserControl

    首先添加一个需要控制的属性

    复制代码

      1 private int splitCount = 10;
      2         /// <summary>
      3         /// Gets or sets the split count.
      4         /// </summary>
      5         /// <value>The split count.</value>
      6         [Description("分隔刻度数量,>1"), Category("自定义")]
      7         public int SplitCount
      8         {
      9             get { return splitCount; }
     10             set
     11             {
     12                 if (value < 1)
     13                     return;
     14                 splitCount = value;
     15                 Refresh();
     16             }
     17         }
     18 
     19         private int meterDegrees = 150;
     20         /// <summary>
     21         /// Gets or sets the meter degrees.
     22         /// </summary>
     23         /// <value>The meter degrees.</value>
     24         [Description("表盘跨度角度,0-360"), Category("自定义")]
     25         public int MeterDegrees
     26         {
     27             get { return meterDegrees; }
     28             set
     29             {
     30                 if (value > 360 || value <= 0)
     31                     return;
     32                 meterDegrees = value;
     33                 Refresh();
     34             }
     35         }
     36 
     37         private decimal minValue = 0;
     38         /// <summary>
     39         /// Gets or sets the minimum value.
     40         /// </summary>
     41         /// <value>The minimum value.</value>
     42         [Description("最小值,<MaxValue"), Category("自定义")]
     43         public decimal MinValue
     44         {
     45             get { return minValue; }
     46             set
     47             {
     48                 if (value >= maxValue)
     49                     return;
     50                 minValue = value;
     51                 Refresh();
     52             }
     53         }
     54 
     55         private decimal maxValue = 100;
     56         /// <summary>
     57         /// Gets or sets the maximum value.
     58         /// </summary>
     59         /// <value>The maximum value.</value>
     60         [Description("最大值,>MinValue"), Category("自定义")]
     61         public decimal MaxValue
     62         {
     63             get { return maxValue; }
     64             set
     65             {
     66                 if (value <= minValue)
     67                     return;
     68                 maxValue = value;
     69                 Refresh();
     70             }
     71         }
     72         /// <summary>
     73         /// 获取或设置控件显示的文字的字体。
     74         /// </summary>
     75         /// <value>The font.</value>
     76         /// <PermissionSet>
     77         ///   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
     78         ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
     79         ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
     80         ///   <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
     81         /// </PermissionSet>
     82         [Description("刻度字体"), Category("自定义")]
     83         public override Font Font
     84         {
     85             get
     86             {
     87                 return base.Font;
     88             }
     89             set
     90             {
     91                 base.Font = value;
     92                 Refresh();
     93             }
     94         }
     95 
     96         private decimal m_value = 0;
     97         /// <summary>
     98         /// Gets or sets the value.
     99         /// </summary>
    100         /// <value>The value.</value>
    101         [Description("值,>=MinValue并且<=MaxValue"), Category("自定义")]
    102         public decimal Value
    103         {
    104             get { return m_value; }
    105             set
    106             {
    107                 if (value < minValue || value > maxValue)
    108                     return;
    109                 m_value = value;
    110                 Refresh();
    111             }
    112         }
    113 
    114         private MeterTextLocation textLocation = MeterTextLocation.None;
    115         /// <summary>
    116         /// Gets or sets the text location.
    117         /// </summary>
    118         /// <value>The text location.</value>
    119         [Description("值和固定文字显示位置"), Category("自定义")]
    120         public MeterTextLocation TextLocation
    121         {
    122             get { return textLocation; }
    123             set
    124             {
    125                 textLocation = value;
    126                 Refresh();
    127             }
    128         }
    129 
    130         private string fixedText;
    131         /// <summary>
    132         /// Gets or sets the fixed text.
    133         /// </summary>
    134         /// <value>The fixed text.</value>
    135         [Description("固定文字"), Category("自定义")]
    136         public string FixedText
    137         {
    138             get { return fixedText; }
    139             set
    140             {
    141                 fixedText = value;
    142                 Refresh();
    143             }
    144         }
    145 
    146         private Font textFont = DefaultFont;
    147         /// <summary>
    148         /// Gets or sets the text font.
    149         /// </summary>
    150         /// <value>The text font.</value>
    151         [Description("值和固定文字字体"), Category("自定义")]
    152         public Font TextFont
    153         {
    154             get { return textFont; }
    155             set
    156             {
    157                 textFont = value;
    158                 Refresh();
    159             }
    160         }
    161 
    162         private Color externalRoundColor = Color.FromArgb(255, 77, 59);
    163         /// <summary>
    164         /// Gets or sets the color of the external round.
    165         /// </summary>
    166         /// <value>The color of the external round.</value>
    167         [Description("外圆颜色"), Category("自定义")]
    168         public Color ExternalRoundColor
    169         {
    170             get { return externalRoundColor; }
    171             set
    172             {
    173                 externalRoundColor = value;
    174                 Refresh();
    175             }
    176         }
    177 
    178         private Color insideRoundColor = Color.FromArgb(255, 77, 59);
    179         /// <summary>
    180         /// Gets or sets the color of the inside round.
    181         /// </summary>
    182         /// <value>The color of the inside round.</value>
    183         [Description("内圆颜色"), Category("自定义")]
    184         public Color InsideRoundColor
    185         {
    186             get { return insideRoundColor; }
    187             set
    188             {
    189                 insideRoundColor = value;
    190                 Refresh();
    191             }
    192         }
    193 
    194         private Color boundaryLineColor = Color.FromArgb(255, 77, 59);
    195         /// <summary>
    196         /// Gets or sets the color of the boundary line.
    197         /// </summary>
    198         /// <value>The color of the boundary line.</value>
    199         [Description("边界线颜色"), Category("自定义")]
    200         public Color BoundaryLineColor
    201         {
    202             get { return boundaryLineColor; }
    203             set
    204             {
    205                 boundaryLineColor = value;
    206                 Refresh();
    207             }
    208         }
    209 
    210         private Color scaleColor = Color.FromArgb(255, 77, 59);
    211         /// <summary>
    212         /// Gets or sets the color of the scale.
    213         /// </summary>
    214         /// <value>The color of the scale.</value>
    215         [Description("刻度颜色"), Category("自定义")]
    216         public Color ScaleColor
    217         {
    218             get { return scaleColor; }
    219             set
    220             {
    221                 scaleColor = value;
    222                 Refresh();
    223             }
    224         }
    225 
    226         private Color scaleValueColor = Color.FromArgb(255, 77, 59);
    227         /// <summary>
    228         /// Gets or sets the color of the scale value.
    229         /// </summary>
    230         /// <value>The color of the scale value.</value>
    231         [Description("刻度值文字颜色"), Category("自定义")]
    232         public Color ScaleValueColor
    233         {
    234             get { return scaleValueColor; }
    235             set
    236             {
    237                 scaleValueColor = value;
    238                 Refresh();
    239             }
    240         }
    241 
    242         private Color pointerColor = Color.FromArgb(255, 77, 59);
    243         /// <summary>
    244         /// Gets or sets the color of the pointer.
    245         /// </summary>
    246         /// <value>The color of the pointer.</value>
    247         [Description("指针颜色"), Category("自定义")]
    248         public Color PointerColor
    249         {
    250             get { return pointerColor; }
    251             set
    252             {
    253                 pointerColor = value;
    254                 Refresh();
    255             }
    256         }
    257 
    258         private Color textColor = Color.FromArgb(255, 77, 59);
    259         /// <summary>
    260         /// Gets or sets the color of the text.
    261         /// </summary>
    262         /// <value>The color of the text.</value>
    263         [Description("值和固定文字颜色"), Category("自定义")]
    264         public Color TextColor
    265         {
    266             get { return textColor; }
    267             set
    268             {
    269                 textColor = value;
    270                 Refresh();
    271             }
    272         }
    273 
    274         Rectangle m_rectWorking;

    复制代码

    重绘

    复制代码

     1  protected override void OnPaint(PaintEventArgs e)
     2         {
     3             base.OnPaint(e);
     4             var g = e.Graphics;
     5             g.SetGDIHigh();
     6 
     7             //外圆
     8             float fltStartAngle = -90 - (meterDegrees) / 2 + 360;
     9             var r1 = new Rectangle(m_rectWorking.Location, new Size(m_rectWorking.Width, m_rectWorking.Width));
    10             g.DrawArc(new Pen(new SolidBrush(externalRoundColor), 1), r1, fltStartAngle, meterDegrees);
    11             //内圆
    12             var r2 = new Rectangle(m_rectWorking.Left + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Top + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Width / 4, m_rectWorking.Width / 4);
    13             g.DrawArc(new Pen(new SolidBrush(insideRoundColor), 1), r2, fltStartAngle, meterDegrees);
    14 
    15             //边界线
    16             if (meterDegrees != 360)
    17             {
    18                 float fltAngle = fltStartAngle - 180;
    19 
    20                 float intY = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
    21                 float intX = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
    22 
    23                 float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Sin(Math.PI * (fltAngle / 180.00F))));
    24                 float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
    25 
    26                 g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(intX, intY), new PointF(fltX1, fltY1));
    27                 g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(m_rectWorking.Right - (fltX1 - m_rectWorking.Left), fltY1), new PointF(m_rectWorking.Right - (intX - m_rectWorking.Left), intY));
    28             }
    29 
    30             //分割线
    31             int _splitCount = splitCount * 2;
    32             float fltSplitValue = (float)meterDegrees / (float)_splitCount;
    33             for (int i = 0; i <= _splitCount; i++)
    34             {
    35                 float fltAngle = (fltStartAngle + fltSplitValue * i - 180) % 360;
    36                 float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
    37                 float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
    38                 float fltY2 = 0;
    39                 float fltX2 = 0;
    40                 if (i % 2 == 0)
    41                 {
    42                     fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
    43                     fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
    44                     if (!(meterDegrees == 360 && i == _splitCount))
    45                     {
    46                         decimal decValue = minValue + (maxValue - minValue) / _splitCount * i;
    47                         var txtSize = g.MeasureString(decValue.ToString("0.##"), this.Font);
    48                         float fltFY1 = (float)(m_rectWorking.Top - txtSize.Height / 2 + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
    49                         float fltFX1 = (float)(m_rectWorking.Left - txtSize.Width / 2 + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
    50                         g.DrawString(decValue.ToString("0.##"), Font, new SolidBrush(scaleValueColor), fltFX1, fltFY1);
    51                     }
    52                 }
    53                 else
    54                 {
    55                     fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
    56                     fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
    57                 }
    58                 g.DrawLine(new Pen(new SolidBrush(scaleColor), i % 2 == 0 ? 2 : 1), new PointF(fltX1, fltY1), new PointF(fltX2, fltY2));
    59             }
    60 
    61             //值文字和固定文字
    62             if (textLocation != MeterTextLocation.None)
    63             {
    64                 string str = m_value.ToString("0.##");
    65                 var txtSize = g.MeasureString(str, textFont);
    66                 float fltY = m_rectWorking.Top + m_rectWorking.Width / 4 - txtSize.Height / 2;
    67                 float fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2;
    68                 g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY));
    69 
    70                 if (!string.IsNullOrEmpty(fixedText))
    71                 {
    72                     str = fixedText;
    73                     txtSize = g.MeasureString(str, textFont);
    74                     fltY = m_rectWorking.Top + m_rectWorking.Width / 4 + txtSize.Height / 2;
    75                     fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2;
    76                     g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY));
    77                 }
    78             }
    79 
    80             //画指针
    81             g.FillEllipse(new SolidBrush(Color.FromArgb(100, pointerColor.R, pointerColor.G, pointerColor.B)), new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 10, m_rectWorking.Top + m_rectWorking.Width / 2 - 10, 20, 20));
    82             g.FillEllipse(Brushes.Red, new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 5, m_rectWorking.Top + m_rectWorking.Width / 2 - 5, 10, 10));
    83             float fltValueAngle = (fltStartAngle + ((float)(m_value - minValue) / (float)(maxValue - minValue)) * (float)meterDegrees - 180) % 360;
    84             float intValueY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Sin(Math.PI * (fltValueAngle / 180.00F))));
    85             float intValueX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Cos(Math.PI * (fltValueAngle / 180.00F)))));
    86             g.DrawLine(new Pen(new SolidBrush(pointerColor), 3), intValueX1, intValueY1, m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + m_rectWorking.Width / 2);
    87         }

    复制代码

    还有一个显示文字位置的枚举

    复制代码

     1 /// <summary>
     2     /// Enum MeterTextLocation
     3     /// </summary>
     4     public enum MeterTextLocation
     5     {
     6         /// <summary>
     7         /// The none
     8         /// </summary>
     9         None,
    10         /// <summary>
    11         /// The top
    12         /// </summary>
    13         Top,
    14         /// <summary>
    15         /// The bottom
    16         /// </summary>
    17         Bottom
    18     }

    复制代码

    代码就这么多了,看完整代码

    // ***********************************************************************
    // Assembly         : HZH_Controls
    // Created          : 2019-09-03
    //
    // ***********************************************************************
    // <copyright file="UCMeter.cs">
    //     Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
    // </copyright>
    //
    // Blog: https://www.cnblogs.com/bfyx
    // GitHub:https://github.com/kwwwvagaa/NetWinformControl
    // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
    //
    // If you use this code, please keep this note.
    // ***********************************************************************
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    
    namespace HZH_Controls.Controls
    {
        /// <summary>
        /// Class UCMeter.
        /// Implements the <see cref="System.Windows.Forms.UserControl" />
        /// </summary>
        /// <seealso cref="System.Windows.Forms.UserControl" />
        public class UCMeter : UserControl
        {
            private int splitCount = 10;
            /// <summary>
            /// Gets or sets the split count.
            /// </summary>
            /// <value>The split count.</value>
            [Description("分隔刻度数量,>1"), Category("自定义")]
            public int SplitCount
            {
                get { return splitCount; }
                set
                {
                    if (value < 1)
                        return;
                    splitCount = value;
                    Refresh();
                }
            }
    
            private int meterDegrees = 150;
            /// <summary>
            /// Gets or sets the meter degrees.
            /// </summary>
            /// <value>The meter degrees.</value>
            [Description("表盘跨度角度,0-360"), Category("自定义")]
            public int MeterDegrees
            {
                get { return meterDegrees; }
                set
                {
                    if (value > 360 || value <= 0)
                        return;
                    meterDegrees = value;
                    Refresh();
                }
            }
    
            private decimal minValue = 0;
            /// <summary>
            /// Gets or sets the minimum value.
            /// </summary>
            /// <value>The minimum value.</value>
            [Description("最小值,<MaxValue"), Category("自定义")]
            public decimal MinValue
            {
                get { return minValue; }
                set
                {
                    if (value >= maxValue)
                        return;
                    minValue = value;
                    Refresh();
                }
            }
    
            private decimal maxValue = 100;
            /// <summary>
            /// Gets or sets the maximum value.
            /// </summary>
            /// <value>The maximum value.</value>
            [Description("最大值,>MinValue"), Category("自定义")]
            public decimal MaxValue
            {
                get { return maxValue; }
                set
                {
                    if (value <= minValue)
                        return;
                    maxValue = value;
                    Refresh();
                }
            }
            /// <summary>
            /// 获取或设置控件显示的文字的字体。
            /// </summary>
            /// <value>The font.</value>
            /// <PermissionSet>
            ///   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
            ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
            ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
            ///   <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
            /// </PermissionSet>
            [Description("刻度字体"), Category("自定义")]
            public override Font Font
            {
                get
                {
                    return base.Font;
                }
                set
                {
                    base.Font = value;
                    Refresh();
                }
            }
    
            private decimal m_value = 0;
            /// <summary>
            /// Gets or sets the value.
            /// </summary>
            /// <value>The value.</value>
            [Description("值,>=MinValue并且<=MaxValue"), Category("自定义")]
            public decimal Value
            {
                get { return m_value; }
                set
                {
                    if (value < minValue || value > maxValue)
                        return;
                    m_value = value;
                    Refresh();
                }
            }
    
            private MeterTextLocation textLocation = MeterTextLocation.None;
            /// <summary>
            /// Gets or sets the text location.
            /// </summary>
            /// <value>The text location.</value>
            [Description("值和固定文字显示位置"), Category("自定义")]
            public MeterTextLocation TextLocation
            {
                get { return textLocation; }
                set
                {
                    textLocation = value;
                    Refresh();
                }
            }
    
            private string fixedText;
            /// <summary>
            /// Gets or sets the fixed text.
            /// </summary>
            /// <value>The fixed text.</value>
            [Description("固定文字"), Category("自定义")]
            public string FixedText
            {
                get { return fixedText; }
                set
                {
                    fixedText = value;
                    Refresh();
                }
            }
    
            private Font textFont = DefaultFont;
            /// <summary>
            /// Gets or sets the text font.
            /// </summary>
            /// <value>The text font.</value>
            [Description("值和固定文字字体"), Category("自定义")]
            public Font TextFont
            {
                get { return textFont; }
                set
                {
                    textFont = value;
                    Refresh();
                }
            }
    
            private Color externalRoundColor = Color.FromArgb(255, 77, 59);
            /// <summary>
            /// Gets or sets the color of the external round.
            /// </summary>
            /// <value>The color of the external round.</value>
            [Description("外圆颜色"), Category("自定义")]
            public Color ExternalRoundColor
            {
                get { return externalRoundColor; }
                set
                {
                    externalRoundColor = value;
                    Refresh();
                }
            }
    
            private Color insideRoundColor = Color.FromArgb(255, 77, 59);
            /// <summary>
            /// Gets or sets the color of the inside round.
            /// </summary>
            /// <value>The color of the inside round.</value>
            [Description("内圆颜色"), Category("自定义")]
            public Color InsideRoundColor
            {
                get { return insideRoundColor; }
                set
                {
                    insideRoundColor = value;
                    Refresh();
                }
            }
    
            private Color boundaryLineColor = Color.FromArgb(255, 77, 59);
            /// <summary>
            /// Gets or sets the color of the boundary line.
            /// </summary>
            /// <value>The color of the boundary line.</value>
            [Description("边界线颜色"), Category("自定义")]
            public Color BoundaryLineColor
            {
                get { return boundaryLineColor; }
                set
                {
                    boundaryLineColor = value;
                    Refresh();
                }
            }
    
            private Color scaleColor = Color.FromArgb(255, 77, 59);
            /// <summary>
            /// Gets or sets the color of the scale.
            /// </summary>
            /// <value>The color of the scale.</value>
            [Description("刻度颜色"), Category("自定义")]
            public Color ScaleColor
            {
                get { return scaleColor; }
                set
                {
                    scaleColor = value;
                    Refresh();
                }
            }
    
            private Color scaleValueColor = Color.FromArgb(255, 77, 59);
            /// <summary>
            /// Gets or sets the color of the scale value.
            /// </summary>
            /// <value>The color of the scale value.</value>
            [Description("刻度值文字颜色"), Category("自定义")]
            public Color ScaleValueColor
            {
                get { return scaleValueColor; }
                set
                {
                    scaleValueColor = value;
                    Refresh();
                }
            }
    
            private Color pointerColor = Color.FromArgb(255, 77, 59);
            /// <summary>
            /// Gets or sets the color of the pointer.
            /// </summary>
            /// <value>The color of the pointer.</value>
            [Description("指针颜色"), Category("自定义")]
            public Color PointerColor
            {
                get { return pointerColor; }
                set
                {
                    pointerColor = value;
                    Refresh();
                }
            }
    
            private Color textColor = Color.FromArgb(255, 77, 59);
            /// <summary>
            /// Gets or sets the color of the text.
            /// </summary>
            /// <value>The color of the text.</value>
            [Description("值和固定文字颜色"), Category("自定义")]
            public Color TextColor
            {
                get { return textColor; }
                set
                {
                    textColor = value;
                    Refresh();
                }
            }
    
            Rectangle m_rectWorking;
            public UCMeter()
            {
                this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
                this.SetStyle(ControlStyles.DoubleBuffer, true);
                this.SetStyle(ControlStyles.ResizeRedraw, true);
                this.SetStyle(ControlStyles.Selectable, true);
                this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
                this.SetStyle(ControlStyles.UserPaint, true);
                this.SizeChanged += UCMeter1_SizeChanged;
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
                this.Size = new Size(350, 200);
            }
    
            void UCMeter1_SizeChanged(object sender, EventArgs e)
            {
                m_rectWorking = new Rectangle(10, 10, this.Width - 20, this.Height - 20);
            }
    
    
            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                var g = e.Graphics;
                g.SetGDIHigh();
    
                //外圆
                float fltStartAngle = -90 - (meterDegrees) / 2 + 360;
                var r1 = new Rectangle(m_rectWorking.Location, new Size(m_rectWorking.Width, m_rectWorking.Width));
                g.DrawArc(new Pen(new SolidBrush(externalRoundColor), 1), r1, fltStartAngle, meterDegrees);
                //内圆
                var r2 = new Rectangle(m_rectWorking.Left + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Top + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Width / 4, m_rectWorking.Width / 4);
                g.DrawArc(new Pen(new SolidBrush(insideRoundColor), 1), r2, fltStartAngle, meterDegrees);
    
                //边界线
                if (meterDegrees != 360)
                {
                    float fltAngle = fltStartAngle - 180;
    
                    float intY = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
                    float intX = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
    
                    float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Sin(Math.PI * (fltAngle / 180.00F))));
                    float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
    
                    g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(intX, intY), new PointF(fltX1, fltY1));
                    g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(m_rectWorking.Right - (fltX1 - m_rectWorking.Left), fltY1), new PointF(m_rectWorking.Right - (intX - m_rectWorking.Left), intY));
                }
    
                //分割线
                int _splitCount = splitCount * 2;
                float fltSplitValue = (float)meterDegrees / (float)_splitCount;
                for (int i = 0; i <= _splitCount; i++)
                {
                    float fltAngle = (fltStartAngle + fltSplitValue * i - 180) % 360;
                    float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
                    float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
                    float fltY2 = 0;
                    float fltX2 = 0;
                    if (i % 2 == 0)
                    {
                        fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
                        fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
                        if (!(meterDegrees == 360 && i == _splitCount))
                        {
                            decimal decValue = minValue + (maxValue - minValue) / _splitCount * i;
                            var txtSize = g.MeasureString(decValue.ToString("0.##"), this.Font);
                            float fltFY1 = (float)(m_rectWorking.Top - txtSize.Height / 2 + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
                            float fltFX1 = (float)(m_rectWorking.Left - txtSize.Width / 2 + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
                            g.DrawString(decValue.ToString("0.##"), Font, new SolidBrush(scaleValueColor), fltFX1, fltFY1);
                        }
                    }
                    else
                    {
                        fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
                        fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
                    }
                    g.DrawLine(new Pen(new SolidBrush(scaleColor), i % 2 == 0 ? 2 : 1), new PointF(fltX1, fltY1), new PointF(fltX2, fltY2));
                }
    
                //值文字和固定文字
                if (textLocation != MeterTextLocation.None)
                {
                    string str = m_value.ToString("0.##");
                    var txtSize = g.MeasureString(str, textFont);
                    float fltY = m_rectWorking.Top + m_rectWorking.Width / 4 - txtSize.Height / 2;
                    float fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2;
                    g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY));
    
                    if (!string.IsNullOrEmpty(fixedText))
                    {
                        str = fixedText;
                        txtSize = g.MeasureString(str, textFont);
                        fltY = m_rectWorking.Top + m_rectWorking.Width / 4 + txtSize.Height / 2;
                        fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2;
                        g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY));
                    }
                }
    
                //画指针
                g.FillEllipse(new SolidBrush(Color.FromArgb(100, pointerColor.R, pointerColor.G, pointerColor.B)), new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 10, m_rectWorking.Top + m_rectWorking.Width / 2 - 10, 20, 20));
                g.FillEllipse(Brushes.Red, new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 5, m_rectWorking.Top + m_rectWorking.Width / 2 - 5, 10, 10));
                float fltValueAngle = (fltStartAngle + ((float)(m_value - minValue) / (float)(maxValue - minValue)) * (float)meterDegrees - 180) % 360;
                float intValueY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Sin(Math.PI * (fltValueAngle / 180.00F))));
                float intValueX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Cos(Math.PI * (fltValueAngle / 180.00F)))));
                g.DrawLine(new Pen(new SolidBrush(pointerColor), 3), intValueX1, intValueY1, m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + m_rectWorking.Width / 2);
            }
        }
    
        /// <summary>
        /// Enum MeterTextLocation
        /// </summary>
        public enum MeterTextLocation
        {
            /// <summary>
            /// The none
            /// </summary>
            None,
            /// <summary>
            /// The top
            /// </summary>
            Top,
            /// <summary>
            /// The bottom
            /// </summary>
            Bottom
        }
    }

    最后的话

    如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧

    展开全文
  • C#做的漂亮的仪表盘。(含源代码)

    热门讨论 2017-11-20 10:51:40
    C#做的漂亮的仪表盘,拖动滚动条仪表盘自动变化,适合工业控制,此控件用来来显示仪表的状态。各个形状都有!
  • Winform表盘控件

    2021-05-06 16:10:15
    Winform,表盘控件
  • 使用wpfGauge进行仪表盘开发,首先需要在官网下载demo,并将其中的WpfGauge.dll进行引用(dll文件我已上传,也可在本文所附的CSDN链接进行下载)。开发步骤如下: 目录 一、引用WpfGauge.dll动态链接库...

    wpfGauge是一款在.NET平台下进行仪表盘界面开发的工具库,其官网地址(可能需要阔学上网)为:https://wpfgauge.codeplex.com/ 。使用wpfGauge进行仪表盘开发,首先需要在官网下载demo,并将其中的WpfGauge.dll进行引用(dll文件我已上传,也可在本文所附的CSDN链接进行下载)。开发步骤如下:

    目录

    一、引用WpfGauge.dll动态链接库文件

    二、创建WPF控件

    1.在解决方案中新建用户控件WPF

    2.编辑xaml文件

    3.根据需求调整xaml设置

    三、在form中添加WPF控件

    1.添加ElementHost

    2.将wpfGauge添加为ElementHost子控件

    四、使用wpfGauge

    1.为wpfGauge添加

    2.在form中调用显示方法


     

    一、引用WpfGauge.dll动态链接库文件

    一般地,将该dll文件放到工程的bin目录下,然后在解决方案中右键“引用”,选择添加引用,如下图:

    在弹出的引用管理器中选择“浏览”,选择dll所在位置,添加引用,如下:

    到此,对wpfGauge的动态链接库引用添加完成,可以开始在项目中进行开发。

    二、创建WPF控件

    1.在解决方案中新建用户控件WPF

    2.编辑xaml文件

    可以从官网的demo中找到该文件,拷贝至刚才创建的文件中,也可以复制下面的代码,注意将namespace和class name该为自己的项目。

    <UserControl x:Class="myNameSpace.gaugeSpeed"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:local="clr-namespace:myNameSpace"
                 mc:Ignorable="d" 
                 d:DesignHeight="450" d:DesignWidth="800"
                 xmlns:gauge="clr-namespace:WpfGauge;assembly=WpfGauge">
        <Grid>
            <Viewbox Grid.Column="1">
    
                <!--这里可以设置
                Value、最大和最小的间隔数,MinValue、MaxValue
                -->
                <gauge:Gauge 
                        FontSize="12" AutoScale="False" Value="0"
                        x:Name="TGauge" MajorTickCount="10" MinorTickCount="5" MinValue="0" MaxValue="100" 
                        HorizontalAlignment="Left"  StartAngle="-65" EndAngle="247" MajorTickMarkColor="LightYellow" Margin="0" Grid.Row="1" VerticalAlignment="Top" Height="200" Width="200">
                    <!--可以设置标记位置,这里设置50处为红色标记-->
                    <gauge:Gauge.GoalMarkers>
                        <gauge:GoalMarker MarkerColor="Red" Value="50" />
                    </gauge:Gauge.GoalMarkers>
                    <!--这里设置Gauge中间的文字-->
                    <gauge:Gauge.ValueTextStyle>
                        <Style TargetType="{x:Type TextBlock}">
                            <Setter Property="Foreground" Value="Yellow"/>
                            <Setter Property="Margin" Value="0,60,0,0" />
                            <Setter Property="FontSize" Value="16"/>
                        </Style>
                    </gauge:Gauge.ValueTextStyle>
                    <!--这里设置周边的尺度数字-->
                    <gauge:Gauge.TickLabelStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="FontSize" Value="14"/>
                        </Style>
                    </gauge:Gauge.TickLabelStyle>
    
                </gauge:Gauge>
            </Viewbox>
        </Grid>
    </UserControl>

    3.根据需求调整xaml设置

    如上的代码中,可以设置指针的初始位置、刻度数字以及标记等。

    三、在form中添加WPF控件

    1.添加ElementHost

    在form的设计文件“工具箱”中选择ElementHost添加至form中

    2.将wpfGauge添加为ElementHost子控件

    如图,选择继承内容为添加的wpfGauge(本项目中命名为gaugeSpeed)。

    四、使用wpfGauge

    1.为wpfGauge添加

    在xaml文件对应的cs文件(即wpfGauge对应的类)中添加方法以进行控件的显示,如更改指针的值等。

    public void setPinValue(int val1)
    {
        TGauge.Value = val1;
    }

    其中,TGauge为xaml文件中设置的gauge名称。 

    2.在form中调用显示方法

    嗯。。调用就可以了~~~

    展开全文
  • 控件动态效果: C#仪表盘控件 控件代码基于WPF 提供Winform调用示例 运行平台net4.0 源码编译平台vs2012
  • C#仿真飞行仪表盘

    2018-12-26 11:53:47
    使用C#编写winform的仿真飞行仪表盘,可实现俯仰角,滚动角,航向角的可视化监测
  • 漂亮的highchart仪表盘

    2014-11-10 14:47:59
    漂亮的highchart仪表盘
  • C# DevExpress GaugeControl控件demo,包括仪表盘、数码管、温度计、交通灯和表情的使用,设置属性和值。 C#源码,vs2008工程,可编译和测试。
  • c# Winform自定义控件-仪表盘功能.docx
  • 自定义view仪表盘显示温度和湿度(仅供参考,具体可根据相关串口协议修改)
  • 绚丽仪表控件,开关控件,彩色圆形按钮,晶体管数字控件源码及测试源码,都已测试,绝对可用 绚丽仪表控件,开关控件,彩色圆形按钮,晶体管数字控件源码及测试源码,都已测试,绝对可用
  • fusionchart支持仪表盘

    2013-03-18 12:41:56
    fusionchart出图时,支持仪表盘展现的简单范例!
  • 因为项目需要做一个电子飞行仪表盘包括地平仪和磁罗盘,网上找了很久,没有找到一个合适的控件,就学习了一些图形处理的开源代码做一个简陋的仪表盘来使用,希望对其他人有帮助,如果有好的建议不妨留言 源程序代码...
  • 仪表盘,dll,电压表,电流表,通用仪表面板。开发好的dll文件,直接导入可使用。控件属性可设置,通过设置,变化仪表盘的形状,颜色,表属性。
  • C#仪表控件.rar

    2020-02-04 10:41:40
    这是C#WinForm的自定义仪表控件,样式类似于汽车的速度表盘,界面比较美观,使用也很方便,当初写软件的时候用到的,分享给大家。
  • 作为自定义控件,效果美观,可实时显示当前值,可设定最大值和最小分度值
  • Iocomp .Net Winform v4.rar

    2019-11-15 20:49:12
    vb仪表盘控件,1、可以在VB6.0、VB.Net、组态王中直接作为控件调用。通过控件属性进行设置及修改仪表控件数值。给有需要的人下载
  • 控件封装很到位,从窗体、弹出窗,控件;到工业用途的温度计,仪表盘,流水管导向都有模拟。能应用到很多地方

空空如也

空空如也

1 2 3 4 5 ... 11
收藏数 215
精华内容 86
关键字:

winform 仪表盘

友情链接: 欧姆龙PLC.rar