در ادامه پست های قبل
پیاده سازی پروژه نقاشی شی گرا *قسمت اول *
پیاده سازی پروژه نقاشی شی گرا *قسمت دوم*
پیاده سازی پروژه نقاشی شی گرا *قسمت سوم*
، در این پست به بررسی کلاس Triangle جهت رسم مثلث و کلاس Diamond جهت رسم لوزی میپردازیم.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
using System.Drawing;
namespace PWS.ObjectOrientedPaint.Models
{ /// <summary>
/// Triangle
/// </summary>
public class Triangle : Shape
{
#region Constructors (2)
/// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class.
/// </summary>
/// <param name="startPoint">The start point.</param>
/// <param name="endPoint">The end point.</param>
/// <param name="zIndex">Index of the z.</param>
/// <param name="foreColor">Color of the fore.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="isFill">if set to <c>true</c> [is fill].</param>
/// <param name="backgroundColor">Color of the background.</param>
public Triangle(PointF startPoint, PointF endPoint, int zIndex, Color foreColor, byte thickness, bool isFill, Color backgroundColor)
: base (startPoint, endPoint, zIndex, foreColor, thickness, isFill, backgroundColor)
{
ShapeType = ShapeType.Triangle;
}
/// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class.
/// </summary>
public Triangle()
{
ShapeType = ShapeType.Triangle;
}
#endregion Constructors
#region Methods (1)
// Public Methods (1)
/// <summary>
/// Draws the specified g.
/// </summary>
/// <param name="g">The g.</param>
public override void Draw(Graphics g)
{
var points = new PointF[3];
points[0] = new PointF(X + Width / 2, Y);
points[1] = new PointF(X + Width, Y + Height);
points[2] = new PointF(X, Y + Height);
if (IsFill)
g.FillPolygon(BackgroundBrush, points);
g.DrawPolygon( new Pen(ForeColor, Thickness), points);
base .Draw(g);
}
#endregion Methods
}
} |