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

前提入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。GitHub:https://github.com/kwwwvagaa/NetWinformControl码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git如果觉得写的还行,请点个star支持一下吧欢迎前来交流探讨:企鹅群568015492麻烦博客下...

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

前提

入行已经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://www.cnblogs.com/bfyx/p/11364884.html

用处及效果

准备工作

请先了解GDI 和三角函数

开始

添加一个类UCValve,继承UserControl

添加一个阀门显示样式枚举

 1 /// <summary> 2  /// Enum ValveStyle 3  /// </summary> 4  public enum ValveStyle 5  { 6/// <summary> 7/// 横向,开关在上方 8/// </summary> 9   Horizontal_Top,10/// <summary>11/// 横向,开关在下方12/// </summary>13   Horizontal_Bottom,14/// <summary>15/// 纵向,开关在左侧16/// </summary>17   Vertical_Left,18/// <summary>19/// 纵向,开关在右侧20/// </summary>21   Vertical_Right,22  }

添加一些属性

  1  /// <summary>  2/// The valve style  3/// </summary>  4private ValveStyle valve ValveStyle.Horizontal_Top;  5   6/// <summary>  7/// Gets or sets the valve style.  8/// </summary>  9/// <value>The valve style.</value> 10[Description("阀门样式"), Category("自定义")] 11public ValveStyle ValveStyle 12   { 13 get { return valveStyle; } 14 set 15 { 16  valve value; 17  Refresh(); 18 } 19   } 20  21/// <summary> 22/// The valve color 23/// </summary> 24private Color valveColor = Color.FromArgb(255, 77, 59); 25  26/// <summary> 27/// Gets or sets the color of the valve. 28/// </summary> 29/// <value>The color of the valve.</value> 30[Description("阀门颜色"), Category("自定义")] 31public Color ValveColor 32   { 33 get { return valveColor; } 34 set 35 { 36  valveColor = value; 37  Refresh(); 38 } 39   } 40  41/// <summary> 42/// The switch color 43/// </summary> 44private Color switchColor = Color.FromArgb(232, 30, 99); 45  46/// <summary> 47/// Gets or sets the color of the switch. 48/// </summary> 49/// <value>The color of the switch.</value> 50[Description("开关把手颜色"), Category("自定义")] 51public Color SwitchColor 52   { 53 get { return switchColor; } 54 set 55 { 56  switchColor = value; 57  Refresh(); 58 } 59   } 60  61/// <summary> 62/// The axis color 63/// </summary> 64private Color axisColor = Color.FromArgb(3, 169, 243); 65  66/// <summary> 67/// Gets or sets the color of the axis. 68/// </summary> 69/// <value>The color of the axis.</value> 70[Description("轴颜色"), Category("自定义")] 71public Color AxisColor 72   { 73 get { return axisColor; } 74 set 75 { 76  axisColor = value; 77  Refresh(
源文地址:https://www.guoxiongfei.cn/cntech/26457.html