⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myline.cs

📁 这是一个用C#编写的画图板程序
💻 CS
字号:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Painter.Common
{
	/// <summary>
	/// Line 的摘要说明。
	/// </summary>
	[Serializable]
	public class MyLine : 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;
			}
		}
		private double length = 0;
		public double Length
		{
			get
			{
				if (length == 0) 
				{
					length = Math.Sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
				}
				return length;
			}
		}
		public MyLine(float x1,float y1,float x2,float y2,
			Color color,float width,DashStyle style)
		{
			this.X1 = x1;
			this.Y1 = y1;
			this.X2 = x2;
			this.Y2 = y2;
			this.BorderColor = color;
			this.BorderWidth = width;
			this.BorderStyle = style;
		}
		public override void Draw(Graphics g,Color bgColor){
			Pen pen = new Pen(this.BorderColor,this.BorderWidth);
			pen.DashStyle = this.BorderStyle;
			g.DrawLine(pen,X1,Y1,X2,Y2);
			if (IsSelected) {
				SolidBrush brush = new SolidBrush(SelectedColor);
				g.FillEllipse(brush,x1-2,y1-2,4,4);
				g.FillEllipse(brush,x2-2,y2-2,4,4);
			}else if (DrawDeSelect){
				SolidBrush brush = new SolidBrush(bgColor);
				g.FillEllipse(brush,x1-2,y1-2,4,4);
				g.FillEllipse(brush,x2-2,y2-2,4,4);

				DrawDeSelect = false;
			}
		}
		public override void Erase(Graphics g,Color bgColor){
			Pen pen = new Pen(bgColor,this.BorderWidth);
			pen.DashStyle = this.BorderStyle;
			g.DrawLine(pen,X1,Y1,X2,Y2);
			if (IsSelected) 
			{
				pen.Color = SelectedColor;
				g.DrawLine(pen,X1,Y1,X2,Y2);
			}
			else if (DrawDeSelect)
			{
				pen.Color = BorderColor;
				g.DrawLine(pen,X1,Y1,X2,Y2);

				DrawDeSelect = false;
			}
		}
		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)
		{
			return LineContains(x1,y1,x2,y2,x,y,this.BorderWidth);
		}
		public override void Rotate(Graphics g, float cx,float cy,
			Color bgColor)
		{
			this.Erase(g,bgColor);
			PointF pt = RotateLine(X1,Y1,cx,cy,Length);
			X2 = pt.X;
			Y2 = pt.Y;
			this.Draw(g,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 + -