官网

http://www.hzhcontrols.com

前提

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

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

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

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

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

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

NuGet

  1. Install-Package HZH_Controls

目录

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

用处及效果

可用作水泵,风机,涡轮等

准备工作

GDI+画的,不懂的可以自行百度一下

开始

添加2个枚举,分别控制进出风口的位置

  1. /// <summary>
  2. /// Enum BlowerEntranceDirection
  3. /// </summary>
  4. public enum BlowerEntranceDirection
  5. {
  6. /// <summary>
  7. /// The none
  8. /// </summary>
  9. None,
  10. /// <summary>
  11. /// The left
  12. /// </summary>
  13. Left,
  14. /// <summary>
  15. /// The right
  16. /// </summary>
  17. Right,
  18. /// <summary>
  19. /// Up
  20. /// </summary>
  21. Up
  22. }
  23.  
  24. /// <summary>
  25. /// Enum BlowerExitDirection
  26. /// </summary>
  27. public enum BlowerExitDirection
  28. {
  29. /// <summary>
  30. /// The left
  31. /// </summary>
  32. Left,
  33. /// <summary>
  34. /// The right
  35. /// </summary>
  36. Right,
  37. /// <summary>
  38. /// Up
  39. /// </summary>
  40. Up
  41. }

属性

  1. /// <summary>
  2. /// The entrance direction
  3. /// </summary>
  4. private BlowerEntranceDirection entranceDirection = BlowerEntranceDirection.None;
  5.  
  6. /// <summary>
  7. /// Gets or sets the entrance direction.
  8. /// </summary>
  9. /// <value>The entrance direction.</value>
  10. [Description("入口方向"), Category("自定义")]
  11. public BlowerEntranceDirection EntranceDirection
  12. {
  13. get { return entranceDirection; }
  14. set
  15. {
  16. entranceDirection = value;
  17. Refresh();
  18. }
  19. }
  20.  
  21. /// <summary>
  22. /// The exit direction
  23. /// </summary>
  24. private BlowerExitDirection exitDirection = BlowerExitDirection.Right;
  25.  
  26. /// <summary>
  27. /// Gets or sets the exit direction.
  28. /// </summary>
  29. /// <value>The exit direction.</value>
  30. [Description("出口方向"), Category("自定义")]
  31. public BlowerExitDirection ExitDirection
  32. {
  33. get { return exitDirection; }
  34. set
  35. {
  36. exitDirection = value;
  37. Refresh();
  38. }
  39. }
  40.  
  41. /// <summary>
  42. /// The blower color
  43. /// </summary>
  44. private Color blowerColor = Color.FromArgb(, , );
  45.  
  46. /// <summary>
  47. /// Gets or sets the color of the blower.
  48. /// </summary>
  49. /// <value>The color of the blower.</value>
  50. [Description("风机颜色"), Category("自定义")]
  51. public Color BlowerColor
  52. {
  53. get { return blowerColor; }
  54. set
  55. {
  56. blowerColor = value;
  57. Refresh();
  58. }
  59. }
  60.  
  61. /// <summary>
  62. /// The fan color
  63. /// </summary>
  64. private Color fanColor = Color.FromArgb(, , );
  65.  
  66. /// <summary>
  67. /// Gets or sets the color of the fan.
  68. /// </summary>
  69. /// <value>The color of the fan.</value>
  70. [Description("风叶颜色"), Category("自定义")]
  71. public Color FanColor
  72. {
  73. get { return fanColor; }
  74. set
  75. {
  76. fanColor = value;
  77. Refresh();
  78. }
  79. }
  80.  
  81. /// <summary>
  82. /// The m rect working
  83. /// </summary>
  84. Rectangle m_rectWorking;

重绘

  1. protected override void OnPaint(PaintEventArgs e)
  2. {
  3. base.OnPaint(e);
  4. var g = e.Graphics;
  5. g.SetGDIHigh();
  6. GraphicsPath pathLineIn = new GraphicsPath();
  7. GraphicsPath pathLineOut = new GraphicsPath();
  8. int intLinePenWidth = ;
  9.  
  10. switch (exitDirection)
  11. {
  12. case BlowerExitDirection.Left:
  13. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(, m_rectWorking.Top, this.Width / , m_rectWorking.Height / - ));
  14. intLinePenWidth = m_rectWorking.Height / - ;
  15. pathLineOut.AddLine(new Point(-, m_rectWorking.Top + (m_rectWorking.Height / - ) / ), new Point(m_rectWorking.Left + m_rectWorking.Width / , m_rectWorking.Top + (m_rectWorking.Height / - ) / ));
  16. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(, m_rectWorking.Top - ), new Point(, m_rectWorking.Top + (m_rectWorking.Height / - ) + ));
  17. break;
  18. case BlowerExitDirection.Right:
  19. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(this.Width / , m_rectWorking.Top, this.Width / , m_rectWorking.Height / - ));
  20. intLinePenWidth = m_rectWorking.Height / - ;
  21. pathLineOut.AddLine(new Point(this.Width + , m_rectWorking.Top + (m_rectWorking.Height / - ) / ), new Point(m_rectWorking.Left + m_rectWorking.Width / , m_rectWorking.Top + (m_rectWorking.Height / - ) / ));
  22. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(this.Width - , m_rectWorking.Top - ), new Point(this.Width - , m_rectWorking.Top + (m_rectWorking.Height / - ) + ));
  23. break;
  24. case BlowerExitDirection.Up:
  25. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(m_rectWorking.Right - (m_rectWorking.Width / - ), , m_rectWorking.Width / - , this.Height / ));
  26. intLinePenWidth = m_rectWorking.Width / - ;
  27. pathLineOut.AddLine(new Point(m_rectWorking.Right - (m_rectWorking.Width / - ) / , -), new Point(m_rectWorking.Right - (m_rectWorking.Width / - ) / , m_rectWorking.Top + m_rectWorking.Height / ));
  28. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(m_rectWorking.Right + , ), new Point(m_rectWorking.Right - (m_rectWorking.Width / - ) - , ));
  29. break;
  30. }
  31.  
  32. switch (entranceDirection)
  33. {
  34. case BlowerEntranceDirection.Left:
  35. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(, m_rectWorking.Bottom - m_rectWorking.Height / + , this.Width / , m_rectWorking.Height / - ));
  36. pathLineIn.AddLine(new Point(-, m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) / ), new Point(m_rectWorking.Left + m_rectWorking.Width / , m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) / ));
  37. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(, m_rectWorking.Bottom - m_rectWorking.Height / + - ), new Point(, m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) + ));
  38. break;
  39. case BlowerEntranceDirection.Right:
  40. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(this.Width / , m_rectWorking.Bottom - m_rectWorking.Height / + , this.Width / , m_rectWorking.Height / - ));
  41. pathLineIn.AddLine(new Point(this.Width + , m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) / ), new Point(m_rectWorking.Left + m_rectWorking.Width / , m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) / ));
  42. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(this.Width - , m_rectWorking.Bottom - m_rectWorking.Height / + - ), new Point(this.Width - , m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) + ));
  43. break;
  44. case BlowerEntranceDirection.Up:
  45. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(m_rectWorking.Left, , m_rectWorking.Width / - , this.Height / ));
  46. pathLineIn.AddLine(new Point(m_rectWorking.Left + (m_rectWorking.Width / - ) / , -), new Point(m_rectWorking.Left + (m_rectWorking.Width / - ) / , m_rectWorking.Top + m_rectWorking.Height / ));
  47. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(m_rectWorking.Left - , ), new Point(m_rectWorking.Left + (m_rectWorking.Width / - ) + , ));
  48. break;
  49. }
  50.  
  51. //渐变色
  52. int _intPenWidth = intLinePenWidth;
  53. int intCount = _intPenWidth / / ;
  54. for (int i = ; i < intCount; i++)
  55. {
  56. int _penWidth = _intPenWidth / - * i;
  57. if (_penWidth <= )
  58. _penWidth = ;
  59. if (entranceDirection != BlowerEntranceDirection.None)
  60. g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(, Color.White.R, Color.White.G, Color.White.B)), _penWidth), pathLineIn);
  61. g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(, Color.White.R, Color.White.G, Color.White.B)), _penWidth), pathLineOut);
  62. if (_penWidth == )
  63. break;
  64. }
  65.  
  66. //底座
  67. GraphicsPath gpDZ = new GraphicsPath();
  68. gpDZ.AddLines(new Point[]
  69. {
  70. new Point( m_rectWorking.Left+m_rectWorking.Width/,m_rectWorking.Top+m_rectWorking.Height/),
  71. new Point(m_rectWorking.Left+,this.Height),
  72. new Point(m_rectWorking.Right-,this.Height)
  73. });
  74. gpDZ.CloseAllFigures();
  75. g.FillPath(new SolidBrush(blowerColor), gpDZ);
  76. g.FillPath(new SolidBrush(Color.FromArgb(, Color.White)), gpDZ);
  77. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(m_rectWorking.Left, this.Height - ), new Point(m_rectWorking.Right, this.Height - ));
  78.  
  79. //中心
  80. g.FillEllipse(new SolidBrush(blowerColor), m_rectWorking);
  81. g.FillEllipse(new SolidBrush(Color.FromArgb(, Color.White)), m_rectWorking);
  82.  
  83. //扇叶
  84. Rectangle _rect = new Rectangle(m_rectWorking.Left + (m_rectWorking.Width - (m_rectWorking.Width / * )) / , m_rectWorking.Top + (m_rectWorking.Height - (m_rectWorking.Width / * )) / , (m_rectWorking.Width / * ), (m_rectWorking.Width / * ));
  85.  
  86. int _splitCount = ;
  87. float fltSplitValue = 360F / (float)_splitCount;
  88. for (int i = ; i <= _splitCount; i++)
  89. {
  90. float fltAngle = (fltSplitValue * i - ) % ;
  91. float fltY1 = (float)(_rect.Top + _rect.Width / - ((_rect.Width / ) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
  92. float fltX1 = (float)(_rect.Left + (_rect.Width / - ((_rect.Width / ) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
  93. float fltY2 = ;
  94. float fltX2 = ;
  95.  
  96. fltY2 = (float)(_rect.Top + _rect.Width / - ((_rect.Width / ) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
  97. fltX2 = (float)(_rect.Left + (_rect.Width / - ((_rect.Width / ) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
  98.  
  99. g.DrawLine(new Pen(new SolidBrush(fanColor), ), new PointF(fltX1, fltY1), new PointF(fltX2, fltY2));
  100. }
  101.  
  102. g.FillEllipse(new SolidBrush(fanColor), new Rectangle(_rect.Left + _rect.Width / - _rect.Width / + , _rect.Top + _rect.Width / - _rect.Width / + , _rect.Width / - , _rect.Width / - ));
  103. g.FillEllipse(new SolidBrush(Color.FromArgb(, Color.White)), new Rectangle(_rect.Left - , _rect.Top - , _rect.Width + , _rect.Height + ));
  104. }

全部代码

  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 2019-09-09
  4. //
  5. // ***********************************************************************
  6. // <copyright file="UCBlower.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Windows.Forms;
  21. using System.Drawing;
  22. using System.Drawing.Drawing2D;
  23. using System.ComponentModel;
  24.  
  25. namespace HZH_Controls.Controls
  26. {
  27. /// <summary>
  28. /// Class UCBlower.
  29. /// Implements the <see cref="System.Windows.Forms.UserControl" />
  30. /// </summary>
  31. /// <seealso cref="System.Windows.Forms.UserControl" />
  32. public class UCBlower : UserControl
  33. {
  34. /// <summary>
  35. /// The entrance direction
  36. /// </summary>
  37. private BlowerEntranceDirection entranceDirection = BlowerEntranceDirection.None;
  38.  
  39. /// <summary>
  40. /// Gets or sets the entrance direction.
  41. /// </summary>
  42. /// <value>The entrance direction.</value>
  43. [Description("入口方向"), Category("自定义")]
  44. public BlowerEntranceDirection EntranceDirection
  45. {
  46. get { return entranceDirection; }
  47. set
  48. {
  49. entranceDirection = value;
  50. Refresh();
  51. }
  52. }
  53.  
  54. /// <summary>
  55. /// The exit direction
  56. /// </summary>
  57. private BlowerExitDirection exitDirection = BlowerExitDirection.Right;
  58.  
  59. /// <summary>
  60. /// Gets or sets the exit direction.
  61. /// </summary>
  62. /// <value>The exit direction.</value>
  63. [Description("出口方向"), Category("自定义")]
  64. public BlowerExitDirection ExitDirection
  65. {
  66. get { return exitDirection; }
  67. set
  68. {
  69. exitDirection = value;
  70. Refresh();
  71. }
  72. }
  73.  
  74. /// <summary>
  75. /// The blower color
  76. /// </summary>
  77. private Color blowerColor = Color.FromArgb(, , );
  78.  
  79. /// <summary>
  80. /// Gets or sets the color of the blower.
  81. /// </summary>
  82. /// <value>The color of the blower.</value>
  83. [Description("风机颜色"), Category("自定义")]
  84. public Color BlowerColor
  85. {
  86. get { return blowerColor; }
  87. set
  88. {
  89. blowerColor = value;
  90. Refresh();
  91. }
  92. }
  93.  
  94. /// <summary>
  95. /// The fan color
  96. /// </summary>
  97. private Color fanColor = Color.FromArgb(, , );
  98.  
  99. /// <summary>
  100. /// Gets or sets the color of the fan.
  101. /// </summary>
  102. /// <value>The color of the fan.</value>
  103. [Description("风叶颜色"), Category("自定义")]
  104. public Color FanColor
  105. {
  106. get { return fanColor; }
  107. set
  108. {
  109. fanColor = value;
  110. Refresh();
  111. }
  112. }
  113.  
  114. /// <summary>
  115. /// The m rect working
  116. /// </summary>
  117. Rectangle m_rectWorking;
  118.  
  119. /// <summary>
  120. /// Initializes a new instance of the <see cref="UCBlower"/> class.
  121. /// </summary>
  122. public UCBlower()
  123. {
  124. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  125. this.SetStyle(ControlStyles.DoubleBuffer, true);
  126. this.SetStyle(ControlStyles.ResizeRedraw, true);
  127. this.SetStyle(ControlStyles.Selectable, true);
  128. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  129. this.SetStyle(ControlStyles.UserPaint, true);
  130. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
  131. this.SizeChanged += UCBlower_SizeChanged;
  132. this.Size = new Size(, );
  133.  
  134. }
  135.  
  136. /// <summary>
  137. /// Handles the SizeChanged event of the UCBlower control.
  138. /// </summary>
  139. /// <param name="sender">The source of the event.</param>
  140. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  141. void UCBlower_SizeChanged(object sender, EventArgs e)
  142. {
  143. int intMin = Math.Min(this.Width, this.Height);
  144. m_rectWorking = new Rectangle((this.Width - (intMin / * )) / , (this.Height - (intMin / * )) / , (intMin / * ), (intMin / * ));
  145. }
  146.  
  147. /// <summary>
  148. /// 引发 <see cref="E:System.Windows.Forms.Control.Paint" /> 事件。
  149. /// </summary>
  150. /// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs" />。</param>
  151. protected override void OnPaint(PaintEventArgs e)
  152. {
  153. base.OnPaint(e);
  154. var g = e.Graphics;
  155. g.SetGDIHigh();
  156. GraphicsPath pathLineIn = new GraphicsPath();
  157. GraphicsPath pathLineOut = new GraphicsPath();
  158. int intLinePenWidth = ;
  159.  
  160. switch (exitDirection)
  161. {
  162. case BlowerExitDirection.Left:
  163. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(, m_rectWorking.Top, this.Width / , m_rectWorking.Height / - ));
  164. intLinePenWidth = m_rectWorking.Height / - ;
  165. pathLineOut.AddLine(new Point(-, m_rectWorking.Top + (m_rectWorking.Height / - ) / ), new Point(m_rectWorking.Left + m_rectWorking.Width / , m_rectWorking.Top + (m_rectWorking.Height / - ) / ));
  166. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(, m_rectWorking.Top - ), new Point(, m_rectWorking.Top + (m_rectWorking.Height / - ) + ));
  167. break;
  168. case BlowerExitDirection.Right:
  169. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(this.Width / , m_rectWorking.Top, this.Width / , m_rectWorking.Height / - ));
  170. intLinePenWidth = m_rectWorking.Height / - ;
  171. pathLineOut.AddLine(new Point(this.Width + , m_rectWorking.Top + (m_rectWorking.Height / - ) / ), new Point(m_rectWorking.Left + m_rectWorking.Width / , m_rectWorking.Top + (m_rectWorking.Height / - ) / ));
  172. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(this.Width - , m_rectWorking.Top - ), new Point(this.Width - , m_rectWorking.Top + (m_rectWorking.Height / - ) + ));
  173. break;
  174. case BlowerExitDirection.Up:
  175. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(m_rectWorking.Right - (m_rectWorking.Width / - ), , m_rectWorking.Width / - , this.Height / ));
  176. intLinePenWidth = m_rectWorking.Width / - ;
  177. pathLineOut.AddLine(new Point(m_rectWorking.Right - (m_rectWorking.Width / - ) / , -), new Point(m_rectWorking.Right - (m_rectWorking.Width / - ) / , m_rectWorking.Top + m_rectWorking.Height / ));
  178. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(m_rectWorking.Right + , ), new Point(m_rectWorking.Right - (m_rectWorking.Width / - ) - , ));
  179. break;
  180. }
  181.  
  182. switch (entranceDirection)
  183. {
  184. case BlowerEntranceDirection.Left:
  185. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(, m_rectWorking.Bottom - m_rectWorking.Height / + , this.Width / , m_rectWorking.Height / - ));
  186. pathLineIn.AddLine(new Point(-, m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) / ), new Point(m_rectWorking.Left + m_rectWorking.Width / , m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) / ));
  187. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(, m_rectWorking.Bottom - m_rectWorking.Height / + - ), new Point(, m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) + ));
  188. break;
  189. case BlowerEntranceDirection.Right:
  190. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(this.Width / , m_rectWorking.Bottom - m_rectWorking.Height / + , this.Width / , m_rectWorking.Height / - ));
  191. pathLineIn.AddLine(new Point(this.Width + , m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) / ), new Point(m_rectWorking.Left + m_rectWorking.Width / , m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) / ));
  192. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(this.Width - , m_rectWorking.Bottom - m_rectWorking.Height / + - ), new Point(this.Width - , m_rectWorking.Bottom - m_rectWorking.Height / + + (m_rectWorking.Height / - ) + ));
  193. break;
  194. case BlowerEntranceDirection.Up:
  195. g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(m_rectWorking.Left, , m_rectWorking.Width / - , this.Height / ));
  196. pathLineIn.AddLine(new Point(m_rectWorking.Left + (m_rectWorking.Width / - ) / , -), new Point(m_rectWorking.Left + (m_rectWorking.Width / - ) / , m_rectWorking.Top + m_rectWorking.Height / ));
  197. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(m_rectWorking.Left - , ), new Point(m_rectWorking.Left + (m_rectWorking.Width / - ) + , ));
  198. break;
  199. }
  200.  
  201. //渐变色
  202. int _intPenWidth = intLinePenWidth;
  203. int intCount = _intPenWidth / / ;
  204. for (int i = ; i < intCount; i++)
  205. {
  206. int _penWidth = _intPenWidth / - * i;
  207. if (_penWidth <= )
  208. _penWidth = ;
  209. if (entranceDirection != BlowerEntranceDirection.None)
  210. g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(, Color.White.R, Color.White.G, Color.White.B)), _penWidth), pathLineIn);
  211. g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(, Color.White.R, Color.White.G, Color.White.B)), _penWidth), pathLineOut);
  212. if (_penWidth == )
  213. break;
  214. }
  215.  
  216. //底座
  217. GraphicsPath gpDZ = new GraphicsPath();
  218. gpDZ.AddLines(new Point[]
  219. {
  220. new Point( m_rectWorking.Left+m_rectWorking.Width/,m_rectWorking.Top+m_rectWorking.Height/),
  221. new Point(m_rectWorking.Left+,this.Height),
  222. new Point(m_rectWorking.Right-,this.Height)
  223. });
  224. gpDZ.CloseAllFigures();
  225. g.FillPath(new SolidBrush(blowerColor), gpDZ);
  226. g.FillPath(new SolidBrush(Color.FromArgb(, Color.White)), gpDZ);
  227. g.DrawLine(new Pen(new SolidBrush(blowerColor), ), new Point(m_rectWorking.Left, this.Height - ), new Point(m_rectWorking.Right, this.Height - ));
  228.  
  229. //中心
  230. g.FillEllipse(new SolidBrush(blowerColor), m_rectWorking);
  231. g.FillEllipse(new SolidBrush(Color.FromArgb(, Color.White)), m_rectWorking);
  232.  
  233. //扇叶
  234. Rectangle _rect = new Rectangle(m_rectWorking.Left + (m_rectWorking.Width - (m_rectWorking.Width / * )) / , m_rectWorking.Top + (m_rectWorking.Height - (m_rectWorking.Width / * )) / , (m_rectWorking.Width / * ), (m_rectWorking.Width / * ));
  235.  
  236. int _splitCount = ;
  237. float fltSplitValue = 360F / (float)_splitCount;
  238. for (int i = ; i <= _splitCount; i++)
  239. {
  240. float fltAngle = (fltSplitValue * i - ) % ;
  241. float fltY1 = (float)(_rect.Top + _rect.Width / - ((_rect.Width / ) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
  242. float fltX1 = (float)(_rect.Left + (_rect.Width / - ((_rect.Width / ) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
  243. float fltY2 = ;
  244. float fltX2 = ;
  245.  
  246. fltY2 = (float)(_rect.Top + _rect.Width / - ((_rect.Width / ) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
  247. fltX2 = (float)(_rect.Left + (_rect.Width / - ((_rect.Width / ) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
  248.  
  249. g.DrawLine(new Pen(new SolidBrush(fanColor), ), new PointF(fltX1, fltY1), new PointF(fltX2, fltY2));
  250. }
  251.  
  252. g.FillEllipse(new SolidBrush(fanColor), new Rectangle(_rect.Left + _rect.Width / - _rect.Width / + , _rect.Top + _rect.Width / - _rect.Width / + , _rect.Width / - , _rect.Width / - ));
  253. g.FillEllipse(new SolidBrush(Color.FromArgb(, Color.White)), new Rectangle(_rect.Left - , _rect.Top - , _rect.Width + , _rect.Height + ));
  254. }
  255. }
  256. /// <summary>
  257. /// Enum BlowerEntranceDirection
  258. /// </summary>
  259. public enum BlowerEntranceDirection
  260. {
  261. /// <summary>
  262. /// The none
  263. /// </summary>
  264. None,
  265. /// <summary>
  266. /// The left
  267. /// </summary>
  268. Left,
  269. /// <summary>
  270. /// The right
  271. /// </summary>
  272. Right,
  273. /// <summary>
  274. /// Up
  275. /// </summary>
  276. Up
  277. }
  278.  
  279. /// <summary>
  280. /// Enum BlowerExitDirection
  281. /// </summary>
  282. public enum BlowerExitDirection
  283. {
  284. /// <summary>
  285. /// The left
  286. /// </summary>
  287. Left,
  288. /// <summary>
  289. /// The right
  290. /// </summary>
  291. Right,
  292. /// <summary>
  293. /// Up
  294. /// </summary>
  295. Up
  296. }
  297. }

添加一个类UCBlower ,继承UserControl

最后的话

如果你喜欢的话,请到 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自定义控件-表格优化

    出处:http://www.hzhcontrols.com/原文:http://www.hzhcontrols.com/blog-149.html本文版权归www.hzhcontrols.com所有欢 ...

  3. (四十六)c#Winform自定义控件-水波进度条-HZHControls

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

  4. (十六)c#Winform自定义控件-文本框哪里去了?-HZHControls

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

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

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

  6. (七十六)c#Winform自定义控件-表单验证组件

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

  7. (三十六)c#Winform自定义控件-步骤控件-HZHControls

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

  8. (六)c#Winform自定义控件-单选框

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

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

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

随机推荐

  1. WPF:事件委托对于不同界面间通信的应用

    界面1内设定点击事件,生成Path用事件传出public partial class TemplateWindow : Window     {         internal delegate v ...

  2. window下打jar包

    比如我的项目在 F/Myjar F:\Myjar>ll'll' 不是内部或外部命令,也不是可运行的程序或批处理文件. F:\Myjar>cd mian系统找不到指定的路径. F:\Myja ...

  3. 二叉查找树(查找、插入、删除)——C语言

    二叉查找树 二叉查找树(BST:Binary Search Tree)是一种特殊的二叉树,它改善了二叉树节点查找的效率.二叉查找树有以下性质: (1)若左子树不空,则左子树上所有节点的值均小于它的根节 ...

  4. 数据结构之最小堆的实现C++版

    完全二叉树之所以用数组的方式存在,在于他的一个特性 若子节点为i,则父节点为(i-1)/2,注意c++特性,该结果肯定是个整数. 若父节点为j,则子节点必为2*j+1;则在数组里面可以非常方便的通过下 ...

  5. Visual Studio Debug

    在watch窗口输入,$err,hr可以看到上一个错误代码和相关描述信息 Error Lookup可以将错误代码转换成为相应的文本描述 FormatMessage()

  6. linux学习总结--linux100day(day2)

    Linux中的哲学--一切皆文件 为了便于操作,我们可以使用secureCRT或Xshell连接到我们的虚拟机. 要用远程工具连接到虚拟机上,我们只需要打开虚拟机上的ssh服务,在xshell中填写主 ...

  7. Java8 CompletableFuture 编程

    一.简介  所谓异步调用其实就是实现一个无需等待被调用函数的返回值而让操作继续运行的方法.在 Java 语言中,简单的讲就是另启一个线程来完成调用中的部分计算,使调用继续运行或返回,而不需要等待计算结 ...

  8. 分布式存储——ceph 的 python 基础接口

    python 使用 boto 库完成分布式存储读.写.判断接口 import boto import boto.s3.connection from boto.s3.key import Key im ...

  9. Python+Selenium - Web自动化测试(一):环境搭建

    清单列表: Python 3x Selenium Chrome Pycharm 一.Python的安装: Python官网下载地址:https://www.python.org/ 1.  进入官网地址 ...

  10. 用 Python 分析上网记录,发现了很多不可思议的事

    摘要:分享个​ Python 神工具.​ 长时间使用浏览器会积累大量浏览器历史记录,这些是很隐私的数据,里面甚至可能有一些不可描述的网站或者搜索记录不想让别人知道. 不过,我们自己可能会感兴趣,天天上 ...