GDI+画的,不懂的可以自行百度一下
开始
添加2个枚举,分别控制进出风口的位置
复制代码
1 ///
2 /// Enum BlowerEntranceDirection
3 ///
4 public enum BlowerEntranceDirection
5 {
6 ///
7 /// The none
8 ///
9 None,
10 ///
11 /// The left
12 ///
13 Left,
14 ///
15 /// The right
16 ///
17 Right,
18 ///
19 /// Up
20 ///
21 Up
22 }
23
24 ///
25 /// Enum BlowerExitDirection
26 ///
27 public enum BlowerExitDirection
28 {
29 ///
30 /// The left
31 ///
32 Left,
33 ///
34 /// The right
35 ///
36 Right,
37 ///
38 /// Up
39 ///
40 Up
41 }
复制代码
属性
复制代码
1 ///
2 /// The entrance direction
3 ///
4 private BlowerEntranceDirection entranceDirection = BlowerEntranceDirection.None;
5
6 ///
7 /// Gets or sets the entrance direction.
8 ///
9 /// The entrance direction.
10 [Description(“入口方向”), Category(“自定义”)]
11 public BlowerEntranceDirection EntranceDirection
12 {
13 get { return entranceDirection; }
14 set
15 {
16 entranceDirection = value;
17 Refresh();
18 }
19 }
20
21 ///
22 /// The exit direction
23 ///
24 private BlowerExitDirection exitDirection = BlowerExitDirection.Right;
25
26 ///
27 /// Gets or sets the exit direction.
28 ///
29 /// The exit direction.
30 [Description(“出口方向”), Category(“自定义”)]
31 public BlowerExitDirection ExitDirection
32 {
33 get { return exitDirection; }
34 set
35 {
36 exitDirection = value;
37 Refresh();
38 }
39 }
40
41 ///
42 /// The blower color
43 ///
44 private Color blowerColor = Color.FromArgb(255, 77, 59);
45
46 ///
47 /// Gets or sets the color of the blower.
48 ///
49 /// The color of the blower.
50 [Description(“风机颜色”), Category(“自定义”)]
51 public Color BlowerColor
52 {
53 get { return blowerColor; }
54 set
55 {
56 blowerColor = value;
57 Refresh();
58 }
59 }
60
61 ///
62 /// The fan color
63 ///
64 private Color fanColor = Color.FromArgb(3, 169, 243);
65
66 ///
67 /// Gets or sets the color of the fan.
68 ///
69 /// The color of the fan.
70 [Description(“风叶颜色”), Category(“自定义”)]
71 public Color FanColor
72 {
73 get { return fanColor; }
74 set
75 {
76 fanColor = value;
77 Refresh();
78 }
79 }
80
81 ///
82 /// The m rect working
83 ///
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 }
复制代码
深圳网站建设www.sz886.com