پیاده سازی پروژه نقاشی (Paint) به صورت شی گرا 2#
نویسنده: صابر فتح الهی
تاریخ: ۱۳۹۱/۱۱/۱۸ ۰:۳۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Net;
namespace PWS.ObjectOrientedPaint.Models
{
/// <summary>
/// Shape (Base Class)
/// </summary>
public abstract partial class Shape
{
#region Fields (1)
private Brush _backgroundBrush;
#endregion Fields
#region Properties (16)
/// <summary>
/// Gets or sets the brush.
/// </summary>
/// <value>
/// The brush.
/// </value>
public Brush BackgroundBrush
{
get { return _backgroundBrush ?? (_backgroundBrush = new SolidBrush(BackgroundColor)); }
private set
{
_backgroundBrush = value ?? new SolidBrush(BackgroundColor);
}
}
/// <summary>
/// Gets or sets the color of the background.
/// </summary>
/// <value>
/// The color of the background.
/// </value>
public Color BackgroundColor { get; set; }
/// <summary>
/// Gets or sets the end point.
/// </summary>
/// <value>
/// The end point.
/// </value>
public PointF EndPoint { get; set; }
/// <summary>
/// Gets or sets the color of the fore.
/// </summary>
/// <value>
/// The color of the fore.
/// </value>
public Color ForeColor { get; set; }
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>
/// The height.
/// </value>
public float Height
{
get
{
return Math.Abs(StartPoint.Y - EndPoint.Y);
}
set
{
if (value > 0)
EndPoint = new PointF(EndPoint.X, StartPoint.Y + value);
}
}
/// <summary>
/// Gets or sets a value indicating whether this instance is fill.
/// </summary>
/// <value>
/// <c>true</c> if this instance is fill; otherwise, <c>false</c>.
/// </value>
public bool IsFill { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is selected.
/// </summary>
/// <value>
/// <c>true</c> if this instance is selected; otherwise, <c>false</c>.
/// </value>
public bool IsSelected { get; set; }
/// <summary>
/// Gets or sets my pen.
/// </summary>
/// <value>
/// My pen.
/// </value>
public Pen Pen
{
get
{
return new Pen(ForeColor, Thickness);
}
}
/// <summary>
/// Gets or sets the type of the shape.
/// </summary>
/// <value>
/// The type of the shape.
/// </value>
public ShapeType ShapeType { get; protected set; }
/// <summary>
/// Gets the size.
/// </summary>
/// <value>
/// The size.
/// </value>
public SizeF Size
{
get
{
return new SizeF(Width, Height);
}
}
/// <summary>
/// Gets or sets the start point.
/// </summary>
/// <value>
/// The start point.
/// </value>
public PointF StartPoint { get; set; }
/// <summary>
/// Gets or sets the thickness.
/// </summary>
/// <value>
/// The thickness.
/// </value>
public byte Thickness { get; set; }
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>
/// The width.
/// </value>
public float Width
{
get
{
return Math.Abs(StartPoint.X - EndPoint.X);
}
set
{
if (value > 0)
EndPoint = new PointF(StartPoint.X + value, EndPoint.Y);
}
}
/// <summary>
/// Gets or sets the X.
/// </summary>
/// <value>
/// The X.
/// </value>
public float X
{
get
{
return StartPoint.X;
}
set
{
if (value > 0)
StartPoint = new PointF(value, StartPoint.Y);
}
}
/// <summary>
/// Gets or sets the Y.
/// </summary>
/// <value>
/// The Y.
/// </value>
public float Y
{
get
{
return StartPoint.Y;
}
set
{
if (value > 0)
StartPoint = new PointF(StartPoint.X, value);
}
}
/// <summary>
/// Gets or sets the index of the Z.
/// </summary>
/// <value>
/// The index of the Z.
/// </value>
public int Zindex { get; set; }
#endregion Properties
}
} private Brush _backgroundBrush;
/// <summary>
/// Gets or sets the brush.
/// </summary>
/// <value>
/// The brush.
/// </value>
public Brush BackgroundBrush
{
get
{
return _backgroundBrush;
}
private set
{
_backgroundBrush = (value != null) ? value : new SolidBrush(BackgroundColor);
}
}
//-------------------------------------[Methode for set brush]--------------------------------------
public virtual void SetBackgroundBrushAsHatch(HatchStyle hatchStyle)
{
HatchBrush brush = new HatchBrush(hatchStyle, BackgroundColor);
BackgroundBrush = brush;
}
public virtual void SetBackgroundBrushAsSolid()
{
SolidBrush brush = new SolidBrush(BackgroundColor);
BackgroundBrush = brush;
}
public virtual void SetBackgroundBrushAsLinearGradient()
{
LinearGradientBrush brush = new LinearGradientBrush(StartPoint, EndPoint, ForeColor, BackgroundColor);
BackgroundBrush = brush;
}