快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

c#Winform自定义控件-仪表盘功能-创新互联

前提

成都创新互联主营合阳网站建设的网络公司,主营网站建设方案,app软件开发,合阳h5小程序制作搭建,合阳网站营销推广欢迎合阳等地区企业咨询

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

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

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

NuGet

Install-Package HZH_Controls

目录

https://www.cnblogs.com/bfyx/p/11364884.html

用处及效果

c# Winform自定义控件-仪表盘功能

准备工作

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

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

开始

添加一个类UCMeter 继承 UserControl

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

private int splitCount = 10;
     /// 
     /// Gets or sets the split count.
     /// 
     /// The split count.
     [Description("分隔刻度数量,>1"), Category("自定义")]
     public int SplitCount
     {
       get { return splitCount; }
      set
      {
        if (value < 1)
          return;
        splitCount = value;
        Refresh();
      }
    }
    private int meterDegrees = 150;
    /// 
    /// Gets or sets the meter degrees.
    /// 
    /// The meter degrees.
    [Description("表盘跨度角度,0-360"), Category("自定义")]
    public int MeterDegrees
    {
      get { return meterDegrees; }
      set
      {
        if (value > 360 || value <= 0)
          return;
        meterDegrees = value;
        Refresh();
      }
    }
    private decimal minValue = 0;
    /// 
    /// Gets or sets the minimum value.
    /// 
    /// The minimum value.
    [Description("最小值,= maxValue)
          return;
        minValue = value;
        Refresh();
      }
    }
    private decimal maxValue = 100;
    /// 
    /// Gets or sets the maximum value.
    /// 
    /// The maximum value.
    [Description("大值,>MinValue"), Category("自定义")]
    public decimal MaxValue
    {
      get { return maxValue; }
      set
      {
        if (value <= minValue)
          return;
        maxValue = value;
        Refresh();
      }
    }
    /// 
    /// 获取或设置控件显示的文字的字体。
    /// 
    /// The font.
    /// 
    ///  
    ///  
    ///  
    ///  
    /// 
    [Description("刻度字体"), Category("自定义")]
    public override Font Font
    {
      get
      {
        return base.Font;
      }
      set
      {
        base.Font = value;
        Refresh();
      }
    }
    private decimal m_value = 0;
    /// 
    /// Gets or sets the value.
    /// 
    /// The 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;
    /// 
    /// Gets or sets the text location.
    /// 
    /// The text location.
    [Description("值和固定文字显示位置"), Category("自定义")]
    public MeterTextLocation TextLocation
    {
      get { return textLocation; }
      set
      {
        textLocation = value;
        Refresh();
      }
    }
    private string fixedText;
    /// 
    /// Gets or sets the fixed text.
    /// 
    /// The fixed text.
    [Description("固定文字"), Category("自定义")]
    public string FixedText
    {
      get { return fixedText; }
      set
      {
        fixedText = value;
        Refresh();
      }
    }
    private Font textFont = DefaultFont;
    /// 
    /// Gets or sets the text font.
    /// 
    /// The text font.
    [Description("值和固定文字字体"), Category("自定义")]
    public Font TextFont
    {
      get { return textFont; }
      set
      {
        textFont = value;
        Refresh();
      }
    }
    private Color externalRoundColor = Color.FromArgb(255, 77, 59);
    /// 
    /// Gets or sets the color of the external round.
    /// 
    /// The color of the external round.
    [Description("外圆颜色"), Category("自定义")]
    public Color ExternalRoundColor
    {
      get { return externalRoundColor; }
      set
      {
        externalRoundColor = value;
        Refresh();
      }
    }
    private Color insideRoundColor = Color.FromArgb(255, 77, 59);
    /// 
    /// Gets or sets the color of the inside round.
    /// 
    /// The color of the inside round.
    [Description("内圆颜色"), Category("自定义")]
    public Color InsideRoundColor
    {
      get { return insideRoundColor; }
      set
      {
        insideRoundColor = value;
        Refresh();
      }
    }
    private Color boundaryLineColor = Color.FromArgb(255, 77, 59);
    /// 
    /// Gets or sets the color of the boundary line.
    /// 
    /// The color of the boundary line.
    [Description("边界线颜色"), Category("自定义")]
    public Color BoundaryLineColor
    {
      get { return boundaryLineColor; }
      set
      {
        boundaryLineColor = value;
        Refresh();
      }
    }
    private Color scaleColor = Color.FromArgb(255, 77, 59);
    /// 
    /// Gets or sets the color of the scale.
    /// 
    /// The color of the scale.
    [Description("刻度颜色"), Category("自定义")]
    public Color ScaleColor
    {
      get { return scaleColor; }
      set
      {
        scaleColor = value;
        Refresh();
      }
    }
    private Color scaleValueColor = Color.FromArgb(255, 77, 59);
    /// 
    /// Gets or sets the color of the scale value.
    /// 
    /// The color of the scale value.
    [Description("刻度值文字颜色"), Category("自定义")]
    public Color ScaleValueColor
    {
      get { return scaleValueColor; }
      set
      {
        scaleValueColor = value;
        Refresh();
      }
    }
    private Color pointerColor = Color.FromArgb(255, 77, 59);
    /// 
    /// Gets or sets the color of the pointer.
    /// 
    /// The color of the pointer.
    [Description("指针颜色"), Category("自定义")]
    public Color PointerColor
    {
      get { return pointerColor; }
      set
      {
        pointerColor = value;
        Refresh();
      }
    }
    private Color textColor = Color.FromArgb(255, 77, 59);
    /// 
    /// Gets or sets the color of the text.
    /// 
    /// The color of the text.
    [Description("值和固定文字颜色"), Category("自定义")]
    public Color TextColor
    {
      get { return textColor; }
      set
      {
        textColor = value;
        Refresh();
      }
    }

    Rectangle m_rectWorking;

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:c#Winform自定义控件-仪表盘功能-创新互联
本文来源:http://6mz.cn/article/cophcp.html

其他资讯