欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

(六十)c#Winform自定义控件-鼓风机(工业)

程序员文章站 2023-11-14 16:55:34
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。 GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:https://gitee.com/kwwwvagaa/net_winform_custom_contr ......

前提

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

github:https://github.com/kwwwvagaa/netwinformcontrol

码云:

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

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

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

nuget

install-package hzh_controls

目录

用处及效果

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

(六十)c#Winform自定义控件-鼓风机(工业)

准备工作

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(255, 77, 59);
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(3, 169, 243);
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 = 0;
  9 
 10             switch (exitdirection)
 11             {
 12                 case blowerexitdirection.left:
 13                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(0, m_rectworking.top, this.width / 2, m_rectworking.height / 2 - 5));
 14                     intlinepenwidth = m_rectworking.height / 2 - 5;
 15                     pathlineout.addline(new point(-10, m_rectworking.top + (m_rectworking.height / 2 - 5) / 2), new point(m_rectworking.left + m_rectworking.width / 2, m_rectworking.top + (m_rectworking.height / 2 - 5) / 2));
 16                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(1, m_rectworking.top - 2), new point(1, m_rectworking.top + (m_rectworking.height / 2 - 5) + 2));
 17                     break;
 18                 case blowerexitdirection.right:
 19                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(this.width / 2, m_rectworking.top, this.width / 2, m_rectworking.height / 2 - 5));
 20                     intlinepenwidth = m_rectworking.height / 2 - 5;
 21                     pathlineout.addline(new point(this.width + 10, m_rectworking.top + (m_rectworking.height / 2 - 5) / 2), new point(m_rectworking.left + m_rectworking.width / 2, m_rectworking.top + (m_rectworking.height / 2 - 5) / 2));
 22                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(this.width - 2, m_rectworking.top - 2), new point(this.width - 2, m_rectworking.top + (m_rectworking.height / 2 - 5) + 2));
 23                     break;
 24                 case blowerexitdirection.up:
 25                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(m_rectworking.right - (m_rectworking.width / 2 - 5), 0, m_rectworking.width / 2 - 5, this.height / 2));
 26                     intlinepenwidth = m_rectworking.width / 2 - 5;
 27                     pathlineout.addline(new point(m_rectworking.right - (m_rectworking.width / 2 - 5) / 2, -10), new point(m_rectworking.right - (m_rectworking.width / 2 - 5) / 2, m_rectworking.top + m_rectworking.height / 2));
 28                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(m_rectworking.right + 2, 1), new point(m_rectworking.right - (m_rectworking.width / 2 - 5) - 2, 1));
 29                     break;
 30             }
 31 
 32             switch (entrancedirection)
 33             {
 34                 case blowerentrancedirection.left:
 35                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(0, m_rectworking.bottom - m_rectworking.height / 2 + 5, this.width / 2, m_rectworking.height / 2 - 5));
 36                     pathlinein.addline(new point(-10, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) / 2), new point(m_rectworking.left + m_rectworking.width / 2, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) / 2));
 37                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(1, m_rectworking.bottom - m_rectworking.height / 2 + 5 - 2), new point(1, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) + 2));
 38                     break;
 39                 case blowerentrancedirection.right:
 40                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(this.width / 2, m_rectworking.bottom - m_rectworking.height / 2 + 5, this.width / 2, m_rectworking.height / 2 - 5));
 41                     pathlinein.addline(new point(this.width + 10, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) / 2), new point(m_rectworking.left + m_rectworking.width / 2, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) / 2));
 42                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(this.width - 2, m_rectworking.bottom - m_rectworking.height / 2 + 5 - 2), new point(this.width - 2, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) + 2));
 43                     break;
 44                 case blowerentrancedirection.up:
 45                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(m_rectworking.left, 0, m_rectworking.width / 2 - 5, this.height / 2));
 46                     pathlinein.addline(new point(m_rectworking.left + (m_rectworking.width / 2 - 5) / 2, -10), new point(m_rectworking.left + (m_rectworking.width / 2 - 5) / 2, m_rectworking.top + m_rectworking.height / 2));
 47                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(m_rectworking.left - 2, 1), new point(m_rectworking.left + (m_rectworking.width / 2 - 5) + 2, 1));
 48                     break;
 49             }
 50 
 51             //渐变色
 52             int _intpenwidth = intlinepenwidth;
 53             int intcount = _intpenwidth / 2 / 4;
 54             for (int i = 0; i < intcount; i++)
 55             {
 56                 int _penwidth = _intpenwidth / 2 - 4 * i;
 57                 if (_penwidth <= 0)
 58                     _penwidth = 1;
 59                 if (entrancedirection != blowerentrancedirection.none)
 60                     g.drawpath(new pen(new solidbrush(color.fromargb(40, color.white.r, color.white.g, color.white.b)), _penwidth), pathlinein);
 61                 g.drawpath(new pen(new solidbrush(color.fromargb(40, color.white.r, color.white.g, color.white.b)), _penwidth), pathlineout);
 62                 if (_penwidth == 1)
 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/2,m_rectworking.top+m_rectworking.height/2),
 71                 new point(m_rectworking.left+2,this.height),
 72                 new point(m_rectworking.right-2,this.height)
 73             });
 74             gpdz.closeallfigures();
 75             g.fillpath(new solidbrush(blowercolor), gpdz);
 76             g.fillpath(new solidbrush(color.fromargb(50, color.white)), gpdz);
 77             g.drawline(new pen(new solidbrush(blowercolor), 3), new point(m_rectworking.left, this.height - 2), new point(m_rectworking.right, this.height - 2));
 78 
 79             //中心
 80             g.fillellipse(new solidbrush(blowercolor), m_rectworking);
 81             g.fillellipse(new solidbrush(color.fromargb(20, color.white)), m_rectworking);
 82 
 83 
 84             //扇叶
 85             rectangle _rect = new rectangle(m_rectworking.left + (m_rectworking.width - (m_rectworking.width / 3 * 2)) / 2, m_rectworking.top + (m_rectworking.height - (m_rectworking.width / 3 * 2)) / 2, (m_rectworking.width / 3 * 2), (m_rectworking.width / 3 * 2));
 86 
 87             int _splitcount = 8;
 88             float fltsplitvalue = 360f / (float)_splitcount;
 89             for (int i = 0; i <= _splitcount; i++)
 90             {
 91                 float fltangle = (fltsplitvalue * i - 180) % 360;
 92                 float flty1 = (float)(_rect.top + _rect.width / 2 - ((_rect.width / 2) * math.sin(math.pi * (fltangle / 180.00f))));
 93                 float fltx1 = (float)(_rect.left + (_rect.width / 2 - ((_rect.width / 2) * math.cos(math.pi * (fltangle / 180.00f)))));
 94                 float flty2 = 0;
 95                 float fltx2 = 0;
 96 
 97                 flty2 = (float)(_rect.top + _rect.width / 2 - ((_rect.width / 4) * math.sin(math.pi * (fltangle / 180.00f))));
 98                 fltx2 = (float)(_rect.left + (_rect.width / 2 - ((_rect.width / 4) * math.cos(math.pi * (fltangle / 180.00f)))));
 99 
100                 g.drawline(new pen(new solidbrush(fancolor), 2), new pointf(fltx1, flty1), new pointf(fltx2, flty2));
101             }
102 
103             g.fillellipse(new solidbrush(fancolor), new rectangle(_rect.left + _rect.width / 2 - _rect.width / 4 + 2, _rect.top + _rect.width / 2 - _rect.width / 4 + 2, _rect.width / 2 - 4, _rect.width / 2 - 4));
104             g.fillellipse(new solidbrush(color.fromargb(50, color.white)), new rectangle(_rect.left - 5, _rect.top - 5, _rect.width + 10, _rect.height + 10));
105         }

全部代码

  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(255, 77, 59);
 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(3, 169, 243);
 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(120, 120);
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 / 3 * 2)) / 2, (this.height - (intmin / 3 * 2)) / 2, (intmin / 3 * 2), (intmin / 3 * 2));
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 = 0;
159 
160             switch (exitdirection)
161             {
162                 case blowerexitdirection.left:
163                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(0, m_rectworking.top, this.width / 2, m_rectworking.height / 2 - 5));
164                     intlinepenwidth = m_rectworking.height / 2 - 5;
165                     pathlineout.addline(new point(-10, m_rectworking.top + (m_rectworking.height / 2 - 5) / 2), new point(m_rectworking.left + m_rectworking.width / 2, m_rectworking.top + (m_rectworking.height / 2 - 5) / 2));
166                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(1, m_rectworking.top - 2), new point(1, m_rectworking.top + (m_rectworking.height / 2 - 5) + 2));
167                     break;
168                 case blowerexitdirection.right:
169                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(this.width / 2, m_rectworking.top, this.width / 2, m_rectworking.height / 2 - 5));
170                     intlinepenwidth = m_rectworking.height / 2 - 5;
171                     pathlineout.addline(new point(this.width + 10, m_rectworking.top + (m_rectworking.height / 2 - 5) / 2), new point(m_rectworking.left + m_rectworking.width / 2, m_rectworking.top + (m_rectworking.height / 2 - 5) / 2));
172                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(this.width - 2, m_rectworking.top - 2), new point(this.width - 2, m_rectworking.top + (m_rectworking.height / 2 - 5) + 2));
173                     break;
174                 case blowerexitdirection.up:
175                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(m_rectworking.right - (m_rectworking.width / 2 - 5), 0, m_rectworking.width / 2 - 5, this.height / 2));
176                     intlinepenwidth = m_rectworking.width / 2 - 5;
177                     pathlineout.addline(new point(m_rectworking.right - (m_rectworking.width / 2 - 5) / 2, -10), new point(m_rectworking.right - (m_rectworking.width / 2 - 5) / 2, m_rectworking.top + m_rectworking.height / 2));
178                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(m_rectworking.right + 2, 1), new point(m_rectworking.right - (m_rectworking.width / 2 - 5) - 2, 1));
179                     break;
180             }
181 
182             switch (entrancedirection)
183             {
184                 case blowerentrancedirection.left:
185                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(0, m_rectworking.bottom - m_rectworking.height / 2 + 5, this.width / 2, m_rectworking.height / 2 - 5));
186                     pathlinein.addline(new point(-10, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) / 2), new point(m_rectworking.left + m_rectworking.width / 2, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) / 2));
187                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(1, m_rectworking.bottom - m_rectworking.height / 2 + 5 - 2), new point(1, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) + 2));
188                     break;
189                 case blowerentrancedirection.right:
190                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(this.width / 2, m_rectworking.bottom - m_rectworking.height / 2 + 5, this.width / 2, m_rectworking.height / 2 - 5));
191                     pathlinein.addline(new point(this.width + 10, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) / 2), new point(m_rectworking.left + m_rectworking.width / 2, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) / 2));
192                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(this.width - 2, m_rectworking.bottom - m_rectworking.height / 2 + 5 - 2), new point(this.width - 2, m_rectworking.bottom - m_rectworking.height / 2 + 5 + (m_rectworking.height / 2 - 5) + 2));
193                     break;
194                 case blowerentrancedirection.up:
195                     g.fillrectangle(new solidbrush(blowercolor), new rectangle(m_rectworking.left, 0, m_rectworking.width / 2 - 5, this.height / 2));
196                     pathlinein.addline(new point(m_rectworking.left + (m_rectworking.width / 2 - 5) / 2, -10), new point(m_rectworking.left + (m_rectworking.width / 2 - 5) / 2, m_rectworking.top + m_rectworking.height / 2));
197                     g.drawline(new pen(new solidbrush(blowercolor), 3), new point(m_rectworking.left - 2, 1), new point(m_rectworking.left + (m_rectworking.width / 2 - 5) + 2, 1));
198                     break;
199             }
200 
201             //渐变色
202             int _intpenwidth = intlinepenwidth;
203             int intcount = _intpenwidth / 2 / 4;
204             for (int i = 0; i < intcount; i++)
205             {
206                 int _penwidth = _intpenwidth / 2 - 4 * i;
207                 if (_penwidth <= 0)
208                     _penwidth = 1;
209                 if (entrancedirection != blowerentrancedirection.none)
210                     g.drawpath(new pen(new solidbrush(color.fromargb(40, color.white.r, color.white.g, color.white.b)), _penwidth), pathlinein);
211                 g.drawpath(new pen(new solidbrush(color.fromargb(40, color.white.r, color.white.g, color.white.b)), _penwidth), pathlineout);
212                 if (_penwidth == 1)
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/2,m_rectworking.top+m_rectworking.height/2),
221                 new point(m_rectworking.left+2,this.height),
222                 new point(m_rectworking.right-2,this.height)
223             });
224             gpdz.closeallfigures();
225             g.fillpath(new solidbrush(blowercolor), gpdz);
226             g.fillpath(new solidbrush(color.fromargb(50, color.white)), gpdz);
227             g.drawline(new pen(new solidbrush(blowercolor), 3), new point(m_rectworking.left, this.height - 2), new point(m_rectworking.right, this.height - 2));
228 
229             //中心
230             g.fillellipse(new solidbrush(blowercolor), m_rectworking);
231             g.fillellipse(new solidbrush(color.fromargb(20, color.white)), m_rectworking);
232 
233 
234             //扇叶
235             rectangle _rect = new rectangle(m_rectworking.left + (m_rectworking.width - (m_rectworking.width / 3 * 2)) / 2, m_rectworking.top + (m_rectworking.height - (m_rectworking.width / 3 * 2)) / 2, (m_rectworking.width / 3 * 2), (m_rectworking.width / 3 * 2));
236 
237             int _splitcount = 8;
238             float fltsplitvalue = 360f / (float)_splitcount;
239             for (int i = 0; i <= _splitcount; i++)
240             {
241                 float fltangle = (fltsplitvalue * i - 180) % 360;
242                 float flty1 = (float)(_rect.top + _rect.width / 2 - ((_rect.width / 2) * math.sin(math.pi * (fltangle / 180.00f))));
243                 float fltx1 = (float)(_rect.left + (_rect.width / 2 - ((_rect.width / 2) * math.cos(math.pi * (fltangle / 180.00f)))));
244                 float flty2 = 0;
245                 float fltx2 = 0;
246 
247                 flty2 = (float)(_rect.top + _rect.width / 2 - ((_rect.width / 4) * math.sin(math.pi * (fltangle / 180.00f))));
248                 fltx2 = (float)(_rect.left + (_rect.width / 2 - ((_rect.width / 4) * math.cos(math.pi * (fltangle / 180.00f)))));
249 
250                 g.drawline(new pen(new solidbrush(fancolor), 2), new pointf(fltx1, flty1), new pointf(fltx2, flty2));
251             }
252 
253             g.fillellipse(new solidbrush(fancolor), new rectangle(_rect.left + _rect.width / 2 - _rect.width / 4 + 2, _rect.top + _rect.width / 2 - _rect.width / 4 + 2, _rect.width / 2 - 4, _rect.width / 2 - 4));
254             g.fillellipse(new solidbrush(color.fromargb(50, color.white)), new rectangle(_rect.left - 5, _rect.top - 5, _rect.width + 10, _rect.height + 10));
255         }
256     }
257     /// <summary>
258     /// enum blowerentrancedirection
259     /// </summary>
260     public enum blowerentrancedirection
261     {
262         /// <summary>
263         /// the none
264         /// </summary>
265         none,
266         /// <summary>
267         /// the left
268         /// </summary>
269         left,
270         /// <summary>
271         /// the right
272         /// </summary>
273         right,
274         /// <summary>
275         /// up
276         /// </summary>
277         up
278     }
279 
280     /// <summary>
281     /// enum blowerexitdirection
282     /// </summary>
283     public enum blowerexitdirection
284     {
285         /// <summary>
286         /// the left
287         /// </summary>
288         left,
289         /// <summary>
290         /// the right
291         /// </summary>
292         right,
293         /// <summary>
294         /// up
295         /// </summary>
296         up
297     }
298 }

 

添加一个类ucblower ,继承usercontrol

最后的话

如果你喜欢的话,请到  点个星星吧