📄 mycircle.cs
字号:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Painter.Common
{
/// <summary>
/// MyCircle 的摘要说明。
/// </summary>
[Serializable]
public class MyCircle : MyItem
{
private float x1,y1,x2,y2;
public float X1
{
get
{
return x1;
}
set
{
x1 = value;
}
}
public float Y1
{
get
{
return y1;
}
set
{
y1 = value;
}
}
public float X2
{
get
{
return x2;
}
set
{
x2 = value;
}
}
public float Y2
{
get
{
return y2;
}
set
{
y2 = value;
}
}
// 圆心
public float X
{
get
{
return (X1+X2)/2;
}
}
public float Y
{
get
{
return (Y1+Y2)/2;
}
}
public float Radius {
get{
return (Math.Abs(X1-X2))/2;
}
}
public MyCircle(float x1,float y1,float x2,float y2,
Color bordercolor,float borderwidth,DashStyle borderstyle)
{
this.X1 = x1;
this.Y1 = y1;
this.X2 = x2;
this.Y2 = y2;
this.BorderColor = bordercolor;
this.BorderWidth = borderwidth;
this.BorderStyle = borderstyle;
}
public override void Draw(Graphics g,Color bgColor)
{
Pen pen = new Pen(this.BorderColor,this.BorderWidth);
pen.DashStyle = this.BorderStyle;
g.DrawEllipse(pen,X1,Y1,X2-X1,Y2-Y1);
if (IsSelected)
{
pen.Color = SelectedColor;
g.DrawEllipse(pen,X1,Y1,X2-X1,Y2-Y1);
}
else if (DrawDeSelect)
{
pen.Color = BorderColor;
g.DrawEllipse(pen,X1,Y1,X2-X1,Y2-Y1);
DrawDeSelect = false;
}
}
public override void Erase(Graphics g,Color bgColor)
{
Pen pen = new Pen(bgColor,this.BorderWidth);
pen.DashStyle = this.BorderStyle;
g.DrawEllipse(pen,X1,Y1,X2-X1,Y2-Y1);
}
public override void Select(Graphics g,Color bgColor)
{
IsSelected = true;;
this.Draw(g,bgColor);
}
public override void DeSelect(Graphics g,Color bgColor)
{
IsSelected = false;
DrawDeSelect = true;
this.Draw(g,bgColor);
}
public override bool Contains(float x, float y)
{
double distance = Math.Sqrt(Math.Pow((x-this.X),2)+Math.Pow((y-this.Y),2));
if (distance < this.Radius + 2 + this.BorderWidth &&
distance > this.Radius - 2 - this.BorderWidth) {
return true;
}
return false;
}
public override void Rotate(Graphics g,float cx,float cy,Color bgColor)
{
}
public override void Move(Graphics g, float ptx_offset, float pty_offset, Color bgColor)
{
this.Erase(g,bgColor);
this.X2 += ptx_offset;
this.Y2 += pty_offset;
this.X1 += ptx_offset;
this.Y1 += pty_offset;
this.Draw(g,bgColor);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -