پیاده سازی پروژه نقاشی (Paint) به صورت شی گرا 5#
نویسنده: صابر فتح الهی
تاریخ: ۱۳۹۱/۱۲/۰۳ ۰:۵۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
using System.Drawing;
namespace PWS.ObjectOrientedPaint.Models
{
/// <summary>
/// Rectangle
/// </summary>
public class Rectangle : Shape
{
#region Constructors (2)
/// <summary>
/// Initializes a new instance of the <see cref="Rectangle" /> 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 Rectangle(PointF startPoint, PointF endPoint, int zIndex, Color foreColor, byte thickness, bool isFill, Color backgroundColor)
: base(startPoint, endPoint, zIndex, foreColor, thickness, isFill, backgroundColor)
{
ShapeType = ShapeType.Rectangle;
}
/// <summary>
/// Initializes a new instance of the <see cref="Rectangle" /> class.
/// </summary>
public Rectangle()
{
ShapeType = ShapeType.Rectangle;
}
#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)
{
if (IsFill)
g.FillRectangle(BackgroundBrush, StartPoint.X, StartPoint.Y, Width, Height);
g.DrawRectangle(Pen, StartPoint.X, StartPoint.Y, Width, Height);
base.Draw(g);
}
#endregion Methods
}
}using System;
using System.Drawing;
namespace PWS.ObjectOrientedPaint.Models
{
/// <summary>
/// Square
/// </summary>
public class Square : Rectangle
{
#region Constructors (2)
/// <summary>
/// Initializes a new instance of the <see cref="Square" /> 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 Square(PointF startPoint, PointF endPoint, int zIndex, Color foreColor, byte thickness, bool isFill, Color backgroundColor)
{
float x = 0, y = 0;
float width = Math.Abs(endPoint.X - startPoint.X);
float height = Math.Abs(endPoint.Y - startPoint.Y);
if (startPoint.X <= endPoint.X && startPoint.Y <= endPoint.Y)
{
x = startPoint.X;
y = startPoint.Y;
}
else if (startPoint.X >= endPoint.X && startPoint.Y >= endPoint.Y)
{
x = endPoint.X;
y = endPoint.Y;
}
else if (startPoint.X >= endPoint.X && startPoint.Y <= endPoint.Y)
{
x = endPoint.X;
y = startPoint.Y;
}
else if (startPoint.X <= endPoint.X && startPoint.Y >= endPoint.Y)
{
x = startPoint.X;
y = endPoint.Y;
}
StartPoint = new PointF(x, y);
var side = Math.Max(width, height);
EndPoint = new PointF(x+side, y+side);
ShapeType = ShapeType.Square;
Zindex = zIndex;
ForeColor = foreColor;
Thickness = thickness;
BackgroundColor = backgroundColor;
IsFill = isFill;
}
/// <summary>
/// Initializes a new instance of the <see cref="Square" /> class.
/// </summary>
public Square()
{
ShapeType = ShapeType.Square;
}
#endregion Constructors
}
}سلام
میتونید از ابزارهای تزریق وابستگی برای تامین وهله مورد نیاز استفاده کنید.