图元的拾取、选择和删除
这里仅列出线条的代码,全局代码可以从附件中下载,里头使用到了接口技术来实现调用众多的图元绘制
using
System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace VCSharp
... {
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem mnuDraw;
private System.Windows.Forms.MenuItem mnuLine;
private System.Windows.Forms.MenuItem mnuArc;
private System.Windows.Forms.MenuItem mnuText;
private System.Windows.Forms.MenuItem mnuEdit;
private System.Windows.Forms.MenuItem mnuSelect;
private System.Windows.Forms.MenuItem mnuSelAll;
private System.Windows.Forms.MenuItem mnuDesel;
private System.Windows.Forms.MenuItem mnuDelete;
private ArrayList ges=new ArrayList();
private ArrayList geSels=new ArrayList();
private ICommand aCommand;
private CCreateLine creLine=new CCreateLine();
private CCreateRectangle creRect=new CCreateRectangle();
private CCreateCircle creCircle=new CCreateCircle();
private CCreateArc creArc=new CCreateArc();
private CCreateText creText=new CCreateText();
private CSelect sel=new CSelect();
private System.Windows.Forms.MenuItem mnuRect;
private System.Windows.Forms.MenuItem mnuCircle;
private Module m=new Module();
public Form1()
...{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.mnuDraw = new System.Windows.Forms.MenuItem();
this.mnuLine = new System.Windows.Forms.MenuItem();
this.mnuRect = new System.Windows.Forms.MenuItem();
this.mnuCircle = new System.Windows.Forms.MenuItem();
this.mnuArc = new System.Windows.Forms.MenuItem();
this.mnuText = new System.Windows.Forms.MenuItem();
this.mnuEdit = new System.Windows.Forms.MenuItem();
this.mnuSelect = new System.Windows.Forms.MenuItem();
this.mnuSelAll = new System.Windows.Forms.MenuItem();
this.mnuDesel = new System.Windows.Forms.MenuItem();
this.mnuDelete = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] ...{
this.mnuDraw,
this.mnuEdit});
//
// mnuDraw
//
this.mnuDraw.Index = 0;
this.mnuDraw.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] ...{
this.mnuLine,
this.mnuRect,
this.mnuCircle,
this.mnuArc,
this.mnuText});
this.mnuDraw.Text = "绘图";
//
// mnuLine
//
this.mnuLine.Index = 0;
this.mnuLine.Text = "直线段";
this.mnuLine.Click += new System.EventHandler(this.mnuLine_Click);
//
// mnuRect
//
this.mnuRect.Index = 1;
this.mnuRect.Text = "矩形";
this.mnuRect.Click += new System.EventHandler(this.mnuRect_Click);
//
// mnuCircle
//
this.mnuCircle.Index = 2;
this.mnuCircle.Text = "圆";
this.mnuCircle.Click += new System.EventHandler(this.mnuCircle_Click);
//
// mnuArc
//
this.mnuArc.Index = 3;
this.mnuArc.Text = "圆弧";
this.mnuArc.Click += new System.EventHandler(this.mnuArc_Click);
//
// mnuText
//
this.mnuText.Index = 4;
this.mnuText.Text = "文本";
this.mnuText.Click += new System.EventHandler(this.mnuText_Click);
//
// mnuEdit
//
this.mnuEdit.Index = 1;
this.mnuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] ...{
this.mnuSelect,
this.mnuSelAll,
this.mnuDesel,
this.mnuDelete});
this.mnuEdit.Text = "编辑";
//
// mnuSelect
//
this.mnuSelect.Index = 0;
this.mnuSelect.Text = "选择";
this.mnuSelect.Click += new System.EventHandler(this.mnuSelect_Click);
//
// mnuSelAll
//
this.mnuSelAll.Index = 1;
this.mnuSelAll.Text = "全选";
this.mnuSelAll.Click += new System.EventHandler(this.mnuSelAll_Click);
//
// mnuDesel
//
this.mnuDesel.Index = 2;
this.mnuDesel.Text = "放弃选择";
this.mnuDesel.Click += new System.EventHandler(this.mnuDesel_Click);
//
// mnuDelete
//
this.mnuDelete.Index = 3;
this.mnuDelete.Text = "删除";
this.mnuDelete.Click += new System.EventHandler(this.mnuDelete_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(768, 433);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Net-CAD";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
...{
Graphics g= this.CreateGraphics();
g.FillRectangle(Brushes.White, this.ClientRectangle);
g.PageUnit = GraphicsUnit.Pixel;
//相对于X轴进行镜像变换
Matrix mat=new Matrix(1, 0, 0, -1, 0, 0);
g.Transform = mat;
Rectangle rect= this.ClientRectangle;
float viewDX = rect.Width / 2;
float viewDY = rect.Height / 2;
float viewScale=1;
m.Coordinate(g,ges,viewDX,viewDY,viewScale);
aCommand=creLine;
}
protected override void OnPaint(PaintEventArgs e)
...{
Graphics g=this.CreateGraphics();
if(ges != null)
...{
if(ges.Count > 0)
...{
m.DrawAll(g,ges);
}
}
if(geSels != null)
...{
if(geSels.Count > 0)
...{
m.DrawSel(g,geSels);
}
}
}
public void Coordinate(Graphics g)
...{
//g.TranslateTransform(viewDX, viewDY, MatrixOrder.Append);
//g.ScaleTransform(viewScale, viewScale, MatrixOrder.Append);
g.Clear(Color.White);
//drawall(g);
}
private void mnuLine_Click(object sender, System.EventArgs e)
...{
aCommand=creLine;
}
private void mnuCircle_Click(object sender, System.EventArgs e)
...{
aCommand=creCircle;
}
private void mnuArc_Click(object sender, System.EventArgs e)
...{
aCommand=creArc;
}
private void mnuText_Click(object sender, System.EventArgs e)
...{
aCommand=creText;
}
protected override void OnMouseDown(MouseEventArgs e)
...{
Graphics g=this.CreateGraphics();
PointF aPos=m.PagetoWorld(new PointF(e.X, e.Y));
if (e.Button==MouseButtons.Left)
...{
aCommand.LButtonDown(g,aPos,ges,geSels);
}
else if(e.Button==MouseButtons.Right)
...{
aCommand.RButtonDown(g,aPos);
}
}
protected override void OnMouseMove(MouseEventArgs e)
...{
try
...{
Graphics g=this.CreateGraphics();
PointF aPos=m.PagetoWorld(new PointF(e.X, e.Y));
aCommand.MouseMove(g,aPos);
}
catch(System.NullReferenceException NullEx)
...{
throw NullEx;
}
catch(System.Exception Ex)
...{
throw Ex;
}
}
private void mnuDelete_Click(object sender, System.EventArgs e)
...{
Graphics g = this.CreateGraphics();
for (int i = 0;i<=geSels.Count - 1;i++)
...{
((CGElement)(geSels[i])).Draw(g, DrawMode.Delete);
ges.Remove(geSels[i]);
}
geSels.RemoveRange(0, geSels.Count);
}
private void mnuSelect_Click(object sender, System.EventArgs e)
...{
aCommand=sel;
}
private void mnuSelAll_Click(object sender, System.EventArgs e)
...{
Graphics g= this.CreateGraphics();
for (int i = 0;i<ges.Count;i++)
...{
geSels.Add(ges[i]);
}
m.DrawSel(g,geSels);
}
private void mnuDesel_Click(object sender, System.EventArgs e)
...{
Graphics g= this.CreateGraphics();
for (int i = 0;i<geSels.Count;i++)
...{
((CGElement)(geSels[i])).Draw(g, DrawMode.Normal );
}
geSels.RemoveRange(0, geSels.Count);
}
private void mnuRect_Click(object sender, System.EventArgs e)
...{
aCommand=creRect;
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace VCSharp
... {
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem mnuDraw;
private System.Windows.Forms.MenuItem mnuLine;
private System.Windows.Forms.MenuItem mnuArc;
private System.Windows.Forms.MenuItem mnuText;
private System.Windows.Forms.MenuItem mnuEdit;
private System.Windows.Forms.MenuItem mnuSelect;
private System.Windows.Forms.MenuItem mnuSelAll;
private System.Windows.Forms.MenuItem mnuDesel;
private System.Windows.Forms.MenuItem mnuDelete;
private ArrayList ges=new ArrayList();
private ArrayList geSels=new ArrayList();
private ICommand aCommand;
private CCreateLine creLine=new CCreateLine();
private CCreateRectangle creRect=new CCreateRectangle();
private CCreateCircle creCircle=new CCreateCircle();
private CCreateArc creArc=new CCreateArc();
private CCreateText creText=new CCreateText();
private CSelect sel=new CSelect();
private System.Windows.Forms.MenuItem mnuRect;
private System.Windows.Forms.MenuItem mnuCircle;
private Module m=new Module();
public Form1()
...{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.mnuDraw = new System.Windows.Forms.MenuItem();
this.mnuLine = new System.Windows.Forms.MenuItem();
this.mnuRect = new System.Windows.Forms.MenuItem();
this.mnuCircle = new System.Windows.Forms.MenuItem();
this.mnuArc = new System.Windows.Forms.MenuItem();
this.mnuText = new System.Windows.Forms.MenuItem();
this.mnuEdit = new System.Windows.Forms.MenuItem();
this.mnuSelect = new System.Windows.Forms.MenuItem();
this.mnuSelAll = new System.Windows.Forms.MenuItem();
this.mnuDesel = new System.Windows.Forms.MenuItem();
this.mnuDelete = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] ...{
this.mnuDraw,
this.mnuEdit});
//
// mnuDraw
//
this.mnuDraw.Index = 0;
this.mnuDraw.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] ...{
this.mnuLine,
this.mnuRect,
this.mnuCircle,
this.mnuArc,
this.mnuText});
this.mnuDraw.Text = "绘图";
//
// mnuLine
//
this.mnuLine.Index = 0;
this.mnuLine.Text = "直线段";
this.mnuLine.Click += new System.EventHandler(this.mnuLine_Click);
//
// mnuRect
//
this.mnuRect.Index = 1;
this.mnuRect.Text = "矩形";
this.mnuRect.Click += new System.EventHandler(this.mnuRect_Click);
//
// mnuCircle
//
this.mnuCircle.Index = 2;
this.mnuCircle.Text = "圆";
this.mnuCircle.Click += new System.EventHandler(this.mnuCircle_Click);
//
// mnuArc
//
this.mnuArc.Index = 3;
this.mnuArc.Text = "圆弧";
this.mnuArc.Click += new System.EventHandler(this.mnuArc_Click);
//
// mnuText
//
this.mnuText.Index = 4;
this.mnuText.Text = "文本";
this.mnuText.Click += new System.EventHandler(this.mnuText_Click);
//
// mnuEdit
//
this.mnuEdit.Index = 1;
this.mnuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] ...{
this.mnuSelect,
this.mnuSelAll,
this.mnuDesel,
this.mnuDelete});
this.mnuEdit.Text = "编辑";
//
// mnuSelect
//
this.mnuSelect.Index = 0;
this.mnuSelect.Text = "选择";
this.mnuSelect.Click += new System.EventHandler(this.mnuSelect_Click);
//
// mnuSelAll
//
this.mnuSelAll.Index = 1;
this.mnuSelAll.Text = "全选";
this.mnuSelAll.Click += new System.EventHandler(this.mnuSelAll_Click);
//
// mnuDesel
//
this.mnuDesel.Index = 2;
this.mnuDesel.Text = "放弃选择";
this.mnuDesel.Click += new System.EventHandler(this.mnuDesel_Click);
//
// mnuDelete
//
this.mnuDelete.Index = 3;
this.mnuDelete.Text = "删除";
this.mnuDelete.Click += new System.EventHandler(this.mnuDelete_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(768, 433);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Net-CAD";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
...{
Graphics g= this.CreateGraphics();
g.FillRectangle(Brushes.White, this.ClientRectangle);
g.PageUnit = GraphicsUnit.Pixel;
//相对于X轴进行镜像变换
Matrix mat=new Matrix(1, 0, 0, -1, 0, 0);
g.Transform = mat;
Rectangle rect= this.ClientRectangle;
float viewDX = rect.Width / 2;
float viewDY = rect.Height / 2;
float viewScale=1;
m.Coordinate(g,ges,viewDX,viewDY,viewScale);
aCommand=creLine;
}
protected override void OnPaint(PaintEventArgs e)
...{
Graphics g=this.CreateGraphics();
if(ges != null)
...{
if(ges.Count > 0)
...{
m.DrawAll(g,ges);
}
}
if(geSels != null)
...{
if(geSels.Count > 0)
...{
m.DrawSel(g,geSels);
}
}
}
public void Coordinate(Graphics g)
...{
//g.TranslateTransform(viewDX, viewDY, MatrixOrder.Append);
//g.ScaleTransform(viewScale, viewScale, MatrixOrder.Append);
g.Clear(Color.White);
//drawall(g);
}
private void mnuLine_Click(object sender, System.EventArgs e)
...{
aCommand=creLine;
}
private void mnuCircle_Click(object sender, System.EventArgs e)
...{
aCommand=creCircle;
}
private void mnuArc_Click(object sender, System.EventArgs e)
...{
aCommand=creArc;
}
private void mnuText_Click(object sender, System.EventArgs e)
...{
aCommand=creText;
}
protected override void OnMouseDown(MouseEventArgs e)
...{
Graphics g=this.CreateGraphics();
PointF aPos=m.PagetoWorld(new PointF(e.X, e.Y));
if (e.Button==MouseButtons.Left)
...{
aCommand.LButtonDown(g,aPos,ges,geSels);
}
else if(e.Button==MouseButtons.Right)
...{
aCommand.RButtonDown(g,aPos);
}
}
protected override void OnMouseMove(MouseEventArgs e)
...{
try
...{
Graphics g=this.CreateGraphics();
PointF aPos=m.PagetoWorld(new PointF(e.X, e.Y));
aCommand.MouseMove(g,aPos);
}
catch(System.NullReferenceException NullEx)
...{
throw NullEx;
}
catch(System.Exception Ex)
...{
throw Ex;
}
}
private void mnuDelete_Click(object sender, System.EventArgs e)
...{
Graphics g = this.CreateGraphics();
for (int i = 0;i<=geSels.Count - 1;i++)
...{
((CGElement)(geSels[i])).Draw(g, DrawMode.Delete);
ges.Remove(geSels[i]);
}
geSels.RemoveRange(0, geSels.Count);
}
private void mnuSelect_Click(object sender, System.EventArgs e)
...{
aCommand=sel;
}
private void mnuSelAll_Click(object sender, System.EventArgs e)
...{
Graphics g= this.CreateGraphics();
for (int i = 0;i<ges.Count;i++)
...{
geSels.Add(ges[i]);
}
m.DrawSel(g,geSels);
}
private void mnuDesel_Click(object sender, System.EventArgs e)
...{
Graphics g= this.CreateGraphics();
for (int i = 0;i<geSels.Count;i++)
...{
((CGElement)(geSels[i])).Draw(g, DrawMode.Normal );
}
geSels.RemoveRange(0, geSels.Count);
}
private void mnuRect_Click(object sender, System.EventArgs e)
...{
aCommand=creRect;
}
}
}
using
System.Drawing;
using System.Collections;
public interface ICommand
... {
void LButtonDown(Graphics g,PointF aPos,ArrayList ges,ArrayList geSels);
void RButtonDown(Graphics g,PointF aPos);
void MouseMove(Graphics g,PointF aPos);
}
using System.Collections;
public interface ICommand
... {
void LButtonDown(Graphics g,PointF aPos,ArrayList ges,ArrayList geSels);
void RButtonDown(Graphics g,PointF aPos);
void MouseMove(Graphics g,PointF aPos);
}
using
System;
using System.Drawing;
using System.Collections;
using System.Drawing.Drawing2D ;
namespace VCSharp
... {
public class Const
...{
public const float PI = 3.1416f;
public const int PickRadius=3;
}
public enum DrawMode
...{
Normal,Selec,Drag,Delete
}
public enum Type
...{
Line,Circle,Arc,Text
}
public enum Style
...{
Solid,Dash,Dot,DashDot,DashDotDot
}
[Serializable()]public class Module...{
public ArrayList ges=new ArrayList();
public ArrayList geSels=new ArrayList();
//判断拾取点是否位于包围矩形中
public bool InBox(CBox aBox, PointF aPos)...{
if (aPos.X > aBox.minX && aPos.Y > aBox.minY && aPos.X < aBox.maxX && aPos.Y < aBox.maxY)
...{
return true;
}
else
...{
return false;
}
}
//计算点与点之间的距离
public float DistPtoP(PointF p1, PointF p2)...{
float dx,dy;
dx = p2.X - p1.X;
dy = p2.Y - p1.Y;
float dist=(float)(Math.Sqrt((dx * dx) + (dy * dy)));
return dist;
}
//计算点间连线与X轴正向之间的夹角
public float GetAngle(PointF p1,PointF p2)...{
float tansita,sita,dx;
float angle=0;
dx = Math.Abs(p2.X - p1.X);
if (p2.X == p1.X)...{dx = 0.0001f;}
tansita = Math.Abs(p2.Y - p1.Y) / dx;
sita = (float)(Math.Atan(tansita));
//如果终点横坐标大于、等于起点横坐标,并且终点纵坐标大于、等于起点纵坐标
if (p2.X >= p1.X && p2.Y >= p1.Y)...{angle=sita;}
//如果终点横坐标小于、等于起点横坐标,并且终点纵坐标大于、等于起点纵坐标
if (p2.X <= p1.X && p2.Y >= p1.Y)...{angle=Const.PI - sita;}
//如果终点横坐标小于、等于起点横坐标,并且终点纵坐标小于、等于起点纵坐标
if (p2.X <= p1.X && p2.Y <= p1.Y) ...{angle=Const.PI + sita;}
//如果终点横坐标大于、等于起点横坐标,并且终点纵坐标小于、等于起点纵坐标
if (p2.X >= p1.X && p2.Y <= p1.Y) ...{angle=Const.PI * 2 - sita;}
return angle;
}
public void DrawAll(Graphics g,ArrayList ges)...{
for(int i = 0;i<ges.Count;i++)...{
CGElement ge=(CGElement)(ges[i]);
ge.Draw(g, DrawMode.Normal);
}
}
public void DrawSel(Graphics g,ArrayList geSels)...{
for(int i = 0;i<geSels.Count;i++)
...{
CGElement ge=(CGElement)(geSels[i]);
ge.Draw(g, DrawMode.Selec);
}
}
public void Coordinate(Graphics g,ArrayList ges,
float viewDX,float viewDY,float viewScale)
...{
g.TranslateTransform(viewDX, viewDY, MatrixOrder.Append);
g.ScaleTransform(viewScale, viewScale, MatrixOrder.Append);
g.Clear(Color.White);
DrawAll(g,ges);
}
//页面坐标转换为通用坐标
public PointF PagetoWorld(PointF ep)...{
Form1 f=new Form1();
Rectangle rect=f.ClientRectangle;
float viewDX=rect.Width/2;
float viewDY=rect.Height/2;
PointF p=new PointF();
p.X = ep.X - viewDX;
p.Y = viewDY-ep.Y;
return p;
}
//通用坐标转换为页面坐标
public PointF WorldtoPage(PointF pp)...{
Form1 f=new Form1();
Rectangle rect=f.ClientRectangle;
float viewDX=rect.Width/2;
float viewDY=rect.Height/2;
PointF p=new PointF();
p.X = pp.X + viewDX;
p.Y = -pp.Y + viewDY;
return p;
}
}
}
using System.Drawing;
using System.Collections;
using System.Drawing.Drawing2D ;
namespace VCSharp
... {
public class Const
...{
public const float PI = 3.1416f;
public const int PickRadius=3;
}
public enum DrawMode
...{
Normal,Selec,Drag,Delete
}
public enum Type
...{
Line,Circle,Arc,Text
}
public enum Style
...{
Solid,Dash,Dot,DashDot,DashDotDot
}
[Serializable()]public class Module...{
public ArrayList ges=new ArrayList();
public ArrayList geSels=new ArrayList();
//判断拾取点是否位于包围矩形中
public bool InBox(CBox aBox, PointF aPos)...{
if (aPos.X > aBox.minX && aPos.Y > aBox.minY && aPos.X < aBox.maxX && aPos.Y < aBox.maxY)
...{
return true;
}
else
...{
return false;
}
}
//计算点与点之间的距离
public float DistPtoP(PointF p1, PointF p2)...{
float dx,dy;
dx = p2.X - p1.X;
dy = p2.Y - p1.Y;
float dist=(float)(Math.Sqrt((dx * dx) + (dy * dy)));
return dist;
}
//计算点间连线与X轴正向之间的夹角
public float GetAngle(PointF p1,PointF p2)...{
float tansita,sita,dx;
float angle=0;
dx = Math.Abs(p2.X - p1.X);
if (p2.X == p1.X)...{dx = 0.0001f;}
tansita = Math.Abs(p2.Y - p1.Y) / dx;
sita = (float)(Math.Atan(tansita));
//如果终点横坐标大于、等于起点横坐标,并且终点纵坐标大于、等于起点纵坐标
if (p2.X >= p1.X && p2.Y >= p1.Y)...{angle=sita;}
//如果终点横坐标小于、等于起点横坐标,并且终点纵坐标大于、等于起点纵坐标
if (p2.X <= p1.X && p2.Y >= p1.Y)...{angle=Const.PI - sita;}
//如果终点横坐标小于、等于起点横坐标,并且终点纵坐标小于、等于起点纵坐标
if (p2.X <= p1.X && p2.Y <= p1.Y) ...{angle=Const.PI + sita;}
//如果终点横坐标大于、等于起点横坐标,并且终点纵坐标小于、等于起点纵坐标
if (p2.X >= p1.X && p2.Y <= p1.Y) ...{angle=Const.PI * 2 - sita;}
return angle;
}
public void DrawAll(Graphics g,ArrayList ges)...{
for(int i = 0;i<ges.Count;i++)...{
CGElement ge=(CGElement)(ges[i]);
ge.Draw(g, DrawMode.Normal);
}
}
public void DrawSel(Graphics g,ArrayList geSels)...{
for(int i = 0;i<geSels.Count;i++)
...{
CGElement ge=(CGElement)(geSels[i]);
ge.Draw(g, DrawMode.Selec);
}
}
public void Coordinate(Graphics g,ArrayList ges,
float viewDX,float viewDY,float viewScale)
...{
g.TranslateTransform(viewDX, viewDY, MatrixOrder.Append);
g.ScaleTransform(viewScale, viewScale, MatrixOrder.Append);
g.Clear(Color.White);
DrawAll(g,ges);
}
//页面坐标转换为通用坐标
public PointF PagetoWorld(PointF ep)...{
Form1 f=new Form1();
Rectangle rect=f.ClientRectangle;
float viewDX=rect.Width/2;
float viewDY=rect.Height/2;
PointF p=new PointF();
p.X = ep.X - viewDX;
p.Y = viewDY-ep.Y;
return p;
}
//通用坐标转换为页面坐标
public PointF WorldtoPage(PointF pp)...{
Form1 f=new Form1();
Rectangle rect=f.ClientRectangle;
float viewDX=rect.Width/2;
float viewDY=rect.Height/2;
PointF p=new PointF();
p.X = pp.X + viewDX;
p.Y = -pp.Y + viewDY;
return p;
}
}
}
using
System;
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CLine 的摘要说明。
/// </summary>
///
//直线段类
public class CLine:CGElement
...{
protected PointF m_Begin;
protected PointF m_End;
Module m=new Module();
public PointF LBegin
...{
get...{return m_Begin;}
set...{m_Begin=value;}
}
public PointF LEnd
...{
get...{return m_End;}
set...{m_End=value;}
}
public CLine()
...{
Init();
}
public CLine(PointF pBegin,PointF pEnd)
...{
Init();
m_Begin=pBegin;
m_End=pEnd;
}
public CLine(CLine aline)
...{
m_Begin=aline.LBegin;
m_End=aline.LEnd;
}
private new void Init()
...{
base.Init();
m_Begin=new PointF(0,0);
m_End=new PointF(0,0);
}
//绘直线段
override public void Draw(Graphics g,DrawMode aDrawMode)
...{
try
...{
long aPen,oldP;
//将控制点的坐标由世界坐标转换为页面坐标
PointF eb=m.WorldtoPage(m_Begin);
PointF ee=m.WorldtoPage(m_End);
//获得当前绘图环境的句柄
IntPtr hdc=g.GetHdc();
//设置画笔参数
int[] penPara=DrawSettings(hdc,aDrawMode);
//创建画笔
aPen=Win32API.CreatePen(penPara[0],penPara[1],penPara[2]);
//把画笔选入绘图环境,并返回原来的画笔
oldP=Win32API.SelectObject(hdc,aPen);
Win32API.LPPOINT prePos=new Win32API.LPPOINT();
//把画笔移动到直线段的起点处
Win32API.MoveToEx(hdc, (int)(eb.X), (int)(eb.Y), prePos);
//绘直线段到终点
Win32API.LineTo(hdc, (int)(ee.X), (int)(ee.Y));
//把原来的画笔选入绘图环境
Win32API.SelectObject(hdc, oldP);
//删除新创建的画笔
Win32API.DeleteObject(aPen);
//释放绘图环境句柄
g.ReleaseHdc(hdc);
}
catch(System.NullReferenceException NullEx)
...{
throw NullEx;
}
catch(System.Exception Ex)
...{
throw Ex;
}
}
//计算包围矩形
override public CBox GetBox()
...{
CBox aBox=new CBox();
if (m_Begin.X==m_End.X)
...{
aBox.minX=m_Begin.X-Const.PickRadius;
aBox.minY=Math.Min(m_Begin.Y,m_End.Y);
aBox.maxX=m_Begin.X+Const.PickRadius;
aBox.maxY=Math.Max(m_Begin.Y,m_End.Y);
}
else if (m_Begin.Y==m_End.Y)
...{
aBox.minX=Math.Min(m_Begin.X,m_End.X);
aBox.minY=m_Begin.Y-Const.PickRadius;
aBox.maxX=Math.Max(m_Begin.X,m_End.X);
aBox.maxY=m_Begin.Y+Const.PickRadius;
}
else
...{
aBox.minX=Math.Min(m_Begin.X,m_End.X);
aBox.minY=Math.Min(m_Begin.Y,m_End.Y);
aBox.maxX=Math.Max(m_Begin.X,m_End.X);
aBox.maxY=Math.Max(m_Begin.Y,m_End.Y);
}
return aBox;
}
//计算点到直线段的距离
private float distPtoL(PointF aPos,CLine aLine)
...{
float px,py,dist;
float distX,distY;
float[] kc;
px=aPos.X;
py=aPos.Y;
//获取直线段的截距式方程,返回斜率和截距
kc=aLine.LineKX();
//如果为水平直线段
if (kc[0]==0)
...{
distX=10000;
distY=Math.Abs(py-aLine.LBegin.Y);
}
//如果为竖直直线段
else if (kc[0]==10000)
...{
distX=Math.Abs(px-aLine.LBegin.X);
distY=10000;
}
//如果为斜线
else
...{
distX=Math.Abs(px-(py-kc[1])/kc[0]);
distY=Math.Abs(py-(kc[0]*px+kc[1]));
}
//返回水平距离和竖直距离之间的小值
dist=Math.Min(distX,distY);
return dist;
}
//计算直线段的截距式方程
private float[] LineKX()
...{
float kc0,kc1;
//若直线段不为竖直线段
if (m_Begin.X!=m_End.X)
...{
kc0=(m_End.Y-m_Begin.Y)/(m_End.X-m_Begin.X);
}
//如果是竖直线段
else
...{
kc0=10000f;
}
//计算截距
kc1=m_Begin.Y-kc0*m_Begin.X;
float[] kc=...{kc0,kc1};
return kc;
}
//拾取直线段
override public bool Pick(PointF aPos)
...{
CBox geBox=new CBox();
//判断拾取点是否在测试包围矩形中,若不是,
//则直线段不被拾取
if (!(m.InBox(GetBox(),aPos)))
...{
return false;
}
else
...{
if (distPtoL(aPos,this)<Const.PickRadius)
...{
return true;
}
else
...{
return false;
}
}
}
//判断拾取点是否位于包围矩形中
private bool InBox(CBox aBox,PointF aPos)
...{
if (aPos.X>aBox.minX && aPos.Y>aBox.minY
&& aPos.X<aBox.maxX && aPos.Y<aBox.maxY)
...{
return true;
}
else
...{
return false;
}
}
}
}
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CLine 的摘要说明。
/// </summary>
///
//直线段类
public class CLine:CGElement
...{
protected PointF m_Begin;
protected PointF m_End;
Module m=new Module();
public PointF LBegin
...{
get...{return m_Begin;}
set...{m_Begin=value;}
}
public PointF LEnd
...{
get...{return m_End;}
set...{m_End=value;}
}
public CLine()
...{
Init();
}
public CLine(PointF pBegin,PointF pEnd)
...{
Init();
m_Begin=pBegin;
m_End=pEnd;
}
public CLine(CLine aline)
...{
m_Begin=aline.LBegin;
m_End=aline.LEnd;
}
private new void Init()
...{
base.Init();
m_Begin=new PointF(0,0);
m_End=new PointF(0,0);
}
//绘直线段
override public void Draw(Graphics g,DrawMode aDrawMode)
...{
try
...{
long aPen,oldP;
//将控制点的坐标由世界坐标转换为页面坐标
PointF eb=m.WorldtoPage(m_Begin);
PointF ee=m.WorldtoPage(m_End);
//获得当前绘图环境的句柄
IntPtr hdc=g.GetHdc();
//设置画笔参数
int[] penPara=DrawSettings(hdc,aDrawMode);
//创建画笔
aPen=Win32API.CreatePen(penPara[0],penPara[1],penPara[2]);
//把画笔选入绘图环境,并返回原来的画笔
oldP=Win32API.SelectObject(hdc,aPen);
Win32API.LPPOINT prePos=new Win32API.LPPOINT();
//把画笔移动到直线段的起点处
Win32API.MoveToEx(hdc, (int)(eb.X), (int)(eb.Y), prePos);
//绘直线段到终点
Win32API.LineTo(hdc, (int)(ee.X), (int)(ee.Y));
//把原来的画笔选入绘图环境
Win32API.SelectObject(hdc, oldP);
//删除新创建的画笔
Win32API.DeleteObject(aPen);
//释放绘图环境句柄
g.ReleaseHdc(hdc);
}
catch(System.NullReferenceException NullEx)
...{
throw NullEx;
}
catch(System.Exception Ex)
...{
throw Ex;
}
}
//计算包围矩形
override public CBox GetBox()
...{
CBox aBox=new CBox();
if (m_Begin.X==m_End.X)
...{
aBox.minX=m_Begin.X-Const.PickRadius;
aBox.minY=Math.Min(m_Begin.Y,m_End.Y);
aBox.maxX=m_Begin.X+Const.PickRadius;
aBox.maxY=Math.Max(m_Begin.Y,m_End.Y);
}
else if (m_Begin.Y==m_End.Y)
...{
aBox.minX=Math.Min(m_Begin.X,m_End.X);
aBox.minY=m_Begin.Y-Const.PickRadius;
aBox.maxX=Math.Max(m_Begin.X,m_End.X);
aBox.maxY=m_Begin.Y+Const.PickRadius;
}
else
...{
aBox.minX=Math.Min(m_Begin.X,m_End.X);
aBox.minY=Math.Min(m_Begin.Y,m_End.Y);
aBox.maxX=Math.Max(m_Begin.X,m_End.X);
aBox.maxY=Math.Max(m_Begin.Y,m_End.Y);
}
return aBox;
}
//计算点到直线段的距离
private float distPtoL(PointF aPos,CLine aLine)
...{
float px,py,dist;
float distX,distY;
float[] kc;
px=aPos.X;
py=aPos.Y;
//获取直线段的截距式方程,返回斜率和截距
kc=aLine.LineKX();
//如果为水平直线段
if (kc[0]==0)
...{
distX=10000;
distY=Math.Abs(py-aLine.LBegin.Y);
}
//如果为竖直直线段
else if (kc[0]==10000)
...{
distX=Math.Abs(px-aLine.LBegin.X);
distY=10000;
}
//如果为斜线
else
...{
distX=Math.Abs(px-(py-kc[1])/kc[0]);
distY=Math.Abs(py-(kc[0]*px+kc[1]));
}
//返回水平距离和竖直距离之间的小值
dist=Math.Min(distX,distY);
return dist;
}
//计算直线段的截距式方程
private float[] LineKX()
...{
float kc0,kc1;
//若直线段不为竖直线段
if (m_Begin.X!=m_End.X)
...{
kc0=(m_End.Y-m_Begin.Y)/(m_End.X-m_Begin.X);
}
//如果是竖直线段
else
...{
kc0=10000f;
}
//计算截距
kc1=m_Begin.Y-kc0*m_Begin.X;
float[] kc=...{kc0,kc1};
return kc;
}
//拾取直线段
override public bool Pick(PointF aPos)
...{
CBox geBox=new CBox();
//判断拾取点是否在测试包围矩形中,若不是,
//则直线段不被拾取
if (!(m.InBox(GetBox(),aPos)))
...{
return false;
}
else
...{
if (distPtoL(aPos,this)<Const.PickRadius)
...{
return true;
}
else
...{
return false;
}
}
}
//判断拾取点是否位于包围矩形中
private bool InBox(CBox aBox,PointF aPos)
...{
if (aPos.X>aBox.minX && aPos.Y>aBox.minY
&& aPos.X<aBox.maxX && aPos.Y<aBox.maxY)
...{
return true;
}
else
...{
return false;
}
}
}
}
using
System;
using System.Collections;
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CCreateLine 的摘要说明。
/// </summary>
///
public class CCreateLine:ICommand
...{
private int m_Step;
private PointF m_Begin;
private PointF m_End;
public CCreateLine()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void LButtonDown(Graphics g,PointF aPos,ArrayList ges,ArrayList geSels)...{
PointF prePos=new PointF();
//记录鼠标左键的单击次数
m_Step+=1;
switch (m_Step)
...{
case 1:
m_Begin=aPos;
m_End=aPos;
break;
case 2:
//重绘并删除前一位置的直线段
prePos=m_Begin;
CLine tempLine=new CLine(m_Begin,m_End);
tempLine.Draw(g,DrawMode.Drag);
tempLine=null;
//绘当前位置的直线段
m_Begin=prePos;
m_End=aPos;
CLine newLine=new CLine(m_Begin,m_End);
newLine.Draw(g,DrawMode.Normal);
ges.Add(newLine);
m_Step=0;
break;
}
}
public void MouseMove(Graphics g,PointF aPos)
...{
try
...{
switch (m_Step)
...{
case 1:
PointF prePos=new PointF();
PointF curPos=new PointF();
prePos=m_End;
curPos=aPos;
CLine tempLine1=new CLine(m_Begin,prePos);
tempLine1.Draw(g,DrawMode.Drag);
tempLine1=null;
//绘当前位置的直线段
CLine tempLine2=new CLine(m_Begin,curPos);
m_End=curPos;
tempLine2.Draw(g,DrawMode.Drag);
tempLine2=null;
break;
}
}
catch(System.NullReferenceException NullEx)
...{
throw NullEx;
}
catch(System.Exception Ex)
...{
throw Ex;
}
}
//单击鼠标右键的绘图行为
public void RButtonDown(Graphics g,PointF aPos)
...{
if (m_Step==1)
...{
CLine tempLine=new CLine(m_Begin,m_End);
tempLine.Draw(g,DrawMode.Drag);
tempLine=null;
}
m_Step=0;
}
}
}
using System.Collections;
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CCreateLine 的摘要说明。
/// </summary>
///
public class CCreateLine:ICommand
...{
private int m_Step;
private PointF m_Begin;
private PointF m_End;
public CCreateLine()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void LButtonDown(Graphics g,PointF aPos,ArrayList ges,ArrayList geSels)...{
PointF prePos=new PointF();
//记录鼠标左键的单击次数
m_Step+=1;
switch (m_Step)
...{
case 1:
m_Begin=aPos;
m_End=aPos;
break;
case 2:
//重绘并删除前一位置的直线段
prePos=m_Begin;
CLine tempLine=new CLine(m_Begin,m_End);
tempLine.Draw(g,DrawMode.Drag);
tempLine=null;
//绘当前位置的直线段
m_Begin=prePos;
m_End=aPos;
CLine newLine=new CLine(m_Begin,m_End);
newLine.Draw(g,DrawMode.Normal);
ges.Add(newLine);
m_Step=0;
break;
}
}
public void MouseMove(Graphics g,PointF aPos)
...{
try
...{
switch (m_Step)
...{
case 1:
PointF prePos=new PointF();
PointF curPos=new PointF();
prePos=m_End;
curPos=aPos;
CLine tempLine1=new CLine(m_Begin,prePos);
tempLine1.Draw(g,DrawMode.Drag);
tempLine1=null;
//绘当前位置的直线段
CLine tempLine2=new CLine(m_Begin,curPos);
m_End=curPos;
tempLine2.Draw(g,DrawMode.Drag);
tempLine2=null;
break;
}
}
catch(System.NullReferenceException NullEx)
...{
throw NullEx;
}
catch(System.Exception Ex)
...{
throw Ex;
}
}
//单击鼠标右键的绘图行为
public void RButtonDown(Graphics g,PointF aPos)
...{
if (m_Step==1)
...{
CLine tempLine=new CLine(m_Begin,m_End);
tempLine.Draw(g,DrawMode.Drag);
tempLine=null;
}
m_Step=0;
}
}
}
using
System;
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CBox 的摘要说明。
/// </summary>
public class CBox
...{
public CBox()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
private float m_minX;
private float m_minY;
private float m_maxX;
private float m_maxY;
public float minX
...{
get...{return m_minX;}
set...{m_minX=value;}
}
public float maxX
...{
get...{return m_maxX;}
set...{m_maxX=value;}
}
public float minY
...{
get...{return m_minY;}
set...{m_minY=value;}
}
public float maxY
...{
get...{return m_maxY;}
set...{m_maxY=value;}
}
}
}
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CBox 的摘要说明。
/// </summary>
public class CBox
...{
public CBox()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
private float m_minX;
private float m_minY;
private float m_maxX;
private float m_maxY;
public float minX
...{
get...{return m_minX;}
set...{m_minX=value;}
}
public float maxX
...{
get...{return m_maxX;}
set...{m_maxX=value;}
}
public float minY
...{
get...{return m_minY;}
set...{m_minY=value;}
}
public float maxY
...{
get...{return m_maxY;}
set...{m_maxY=value;}
}
}
}
using
System;
using System.Collections;
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CSelect 的摘要说明。
/// </summary>
public class CSelect:ICommand
...{
public CSelect()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
//单击鼠标左键时的绘图行为
public void LButtonDown(Graphics g, PointF aPos,ArrayList ges,ArrayList geSels)
...{
for(int i = 0;i<ges.Count;i++)
...{
//如果图元被拾取,则用选择模式绘制图元
//并将该图元添加到选择集中去
if (((CGElement)(ges[i])).Pick(aPos))
...{
((CGElement)(ges[i])).Draw(g, DrawMode.Selec);
geSels.Add(ges[i]);
}
}
}
public void MouseMove(Graphics g, PointF aPos)
...{
}
public void RButtonDown(Graphics g, PointF aPos)
...{
}
}
}
using System.Collections;
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CSelect 的摘要说明。
/// </summary>
public class CSelect:ICommand
...{
public CSelect()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
//单击鼠标左键时的绘图行为
public void LButtonDown(Graphics g, PointF aPos,ArrayList ges,ArrayList geSels)
...{
for(int i = 0;i<ges.Count;i++)
...{
//如果图元被拾取,则用选择模式绘制图元
//并将该图元添加到选择集中去
if (((CGElement)(ges[i])).Pick(aPos))
...{
((CGElement)(ges[i])).Draw(g, DrawMode.Selec);
geSels.Add(ges[i]);
}
}
}
public void MouseMove(Graphics g, PointF aPos)
...{
}
public void RButtonDown(Graphics g, PointF aPos)
...{
}
}
}
using
System;
using System.Collections;
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CCreateLine 的摘要说明。
/// </summary>
///
public class CCreateLine:ICommand
...{
private int m_Step;
private PointF m_Begin;
private PointF m_End;
public CCreateLine()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void LButtonDown(Graphics g,PointF aPos,ArrayList ges,ArrayList geSels)...{
PointF prePos=new PointF();
//记录鼠标左键的单击次数
m_Step+=1;
switch (m_Step)
...{
case 1:
m_Begin=aPos;
m_End=aPos;
break;
case 2:
//重绘并删除前一位置的直线段
prePos=m_Begin;
CLine tempLine=new CLine(m_Begin,m_End);
tempLine.Draw(g,DrawMode.Drag);
tempLine=null;
//绘当前位置的直线段
m_Begin=prePos;
m_End=aPos;
CLine newLine=new CLine(m_Begin,m_End);
newLine.Draw(g,DrawMode.Normal);
ges.Add(newLine);
m_Step=0;
break;
}
}
public void MouseMove(Graphics g,PointF aPos)
...{
try
...{
switch (m_Step)
...{
case 1:
PointF prePos=new PointF();
PointF curPos=new PointF();
prePos=m_End;
curPos=aPos;
CLine tempLine1=new CLine(m_Begin,prePos);
tempLine1.Draw(g,DrawMode.Drag);
tempLine1=null;
//绘当前位置的直线段
CLine tempLine2=new CLine(m_Begin,curPos);
m_End=curPos;
tempLine2.Draw(g,DrawMode.Drag);
tempLine2=null;
break;
}
}
catch(System.NullReferenceException NullEx)
...{
throw NullEx;
}
catch(System.Exception Ex)
...{
throw Ex;
}
}
//单击鼠标右键的绘图行为
public void RButtonDown(Graphics g,PointF aPos)
...{
if (m_Step==1)
...{
CLine tempLine=new CLine(m_Begin,m_End);
tempLine.Draw(g,DrawMode.Drag);
tempLine=null;
}
m_Step=0;
}
}
}
using System.Collections;
using System.Drawing;
namespace VCSharp
... {
/**//// <summary>
/// CCreateLine 的摘要说明。
/// </summary>
///
public class CCreateLine:ICommand
...{
private int m_Step;
private PointF m_Begin;
private PointF m_End;
public CCreateLine()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void LButtonDown(Graphics g,PointF aPos,ArrayList ges,ArrayList geSels)...{
PointF prePos=new PointF();
//记录鼠标左键的单击次数
m_Step+=1;
switch (m_Step)
...{
case 1:
m_Begin=aPos;
m_End=aPos;
break;
case 2:
//重绘并删除前一位置的直线段
prePos=m_Begin;
CLine tempLine=new CLine(m_Begin,m_End);
tempLine.Draw(g,DrawMode.Drag);
tempLine=null;
//绘当前位置的直线段
m_Begin=prePos;
m_End=aPos;
CLine newLine=new CLine(m_Begin,m_End);
newLine.Draw(g,DrawMode.Normal);
ges.Add(newLine);
m_Step=0;
break;
}
}
public void MouseMove(Graphics g,PointF aPos)
...{
try
...{
switch (m_Step)
...{
case 1:
PointF prePos=new PointF();
PointF curPos=new PointF();
prePos=m_End;
curPos=aPos;
CLine tempLine1=new CLine(m_Begin,prePos);
tempLine1.Draw(g,DrawMode.Drag);
tempLine1=null;
//绘当前位置的直线段
CLine tempLine2=new CLine(m_Begin,curPos);
m_End=curPos;
tempLine2.Draw(g,DrawMode.Drag);
tempLine2=null;
break;
}
}
catch(System.NullReferenceException NullEx)
...{
throw NullEx;
}
catch(System.Exception Ex)
...{
throw Ex;
}
}
//单击鼠标右键的绘图行为
public void RButtonDown(Graphics g,PointF aPos)
...{
if (m_Step==1)
...{
CLine tempLine=new CLine(m_Begin,m_End);
tempLine.Draw(g,DrawMode.Drag);
tempLine=null;
}
m_Step=0;
}
}
}
using
System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace VCSharp
... {
/**//// <summary>
/// CGElement 的摘要说明。
/// </summary>
public abstract class CGElement
...{
private int m_Color;
private int m_Style;
private int m_Width;
public int Color
...{
get...{return m_Color;}
set...{m_Color=value;}
}
public int Style
...{
get...{return m_Style;}
set...{m_Style=value;}
}
public int Width
...{
get...{return m_Width;}
set...{m_Width=value;}
}
public CGElement()
...{
Init();
}
//初始化图元
protected void Init()
...{
m_Style=0;
m_Width=1;
m_Color=0;
}
//绘制图元
abstract public void Draw(Graphics g,DrawMode aDrawMode);
//获取图元的包围矩形
abstract public CBox GetBox();
//拾取图元
abstract public bool Pick(PointF aPos);
//根据不同的绘图模式设置不同的绘图参数
public int[] DrawSettings(IntPtr hdc,DrawMode aDrawMode)
...{
switch(aDrawMode)
...{
case DrawMode.Normal:
Win32API.SetROP2(hdc, 13);
m_Style = 0;
m_Width = 1;
m_Color =0;
break;
case DrawMode.Selec:
Win32API.SetROP2(hdc, 13);
m_Style = 1;
m_Width = 1;
m_Color =255;
break;
case DrawMode.Drag:
Win32API.SetROP2(hdc, 10);
m_Style = 0;
m_Width = 1;
m_Color =16711680;
break;
case DrawMode.Delete:
Win32API.SetROP2(hdc, 13);
m_Style = 0;
m_Width = 1;
m_Color =16777215;
break;
}
int[] penPara=...{m_Style,m_Width,m_Color};
return penPara;
}
}
}
using System.Drawing;
using System.Drawing.Drawing2D;
namespace VCSharp
... {
/**//// <summary>
/// CGElement 的摘要说明。
/// </summary>
public abstract class CGElement
...{
private int m_Color;
private int m_Style;
private int m_Width;
public int Color
...{
get...{return m_Color;}
set...{m_Color=value;}
}
public int Style
...{
get...{return m_Style;}
set...{m_Style=value;}
}
public int Width
...{
get...{return m_Width;}
set...{m_Width=value;}
}
public CGElement()
...{
Init();
}
//初始化图元
protected void Init()
...{
m_Style=0;
m_Width=1;
m_Color=0;
}
//绘制图元
abstract public void Draw(Graphics g,DrawMode aDrawMode);
//获取图元的包围矩形
abstract public CBox GetBox();
//拾取图元
abstract public bool Pick(PointF aPos);
//根据不同的绘图模式设置不同的绘图参数
public int[] DrawSettings(IntPtr hdc,DrawMode aDrawMode)
...{
switch(aDrawMode)
...{
case DrawMode.Normal:
Win32API.SetROP2(hdc, 13);
m_Style = 0;
m_Width = 1;
m_Color =0;
break;
case DrawMode.Selec:
Win32API.SetROP2(hdc, 13);
m_Style = 1;
m_Width = 1;
m_Color =255;
break;
case DrawMode.Drag:
Win32API.SetROP2(hdc, 10);
m_Style = 0;
m_Width = 1;
m_Color =16711680;
break;
case DrawMode.Delete:
Win32API.SetROP2(hdc, 13);
m_Style = 0;
m_Width = 1;
m_Color =16777215;
break;
}
int[] penPara=...{m_Style,m_Width,m_Color};
return penPara;
}
}
}
http://dl2.csdn.net/down4/20070630/30173714593.rar