C#怎样实现像CAD画图?

来源:百度知道 编辑:UC知道 时间:2024/05/05 11:19:40
怎么实现像CAD一样绘图?如绘制一条直线,点直线命令,进入直线绘制模式,在区域确定第一个点后,随着鼠标移动线条也随着移动,直到第二点确定,请教高手指教!

画图是一门很深的学问,而且基本上一个人是很难完成的,如果想简单的模拟的画,可以参考下面的程序:
public partial class Form1 : Form
{
bool DrawLine = false;//标志是否进入画线状态
Graphics g;//GDI+对象
Point Pt1;//
Point Pt2;//两个端点,用于画线的
public Form1()
{
InitializeComponent();
g = Graphics.FromHwnd(this.Handle);//创建一个新的GDI+对象
Pt1 = new Point();
Pt2 = new Point();
}

private void button1_Click(object sender, EventArgs e)
{//一个按钮,按下的时候进入画线状态,再按一次退出画线状态
if (DrawLine)
{
DrawLine = false;
}
else
{
DrawLine = true;
}
}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{//按下鼠标时发生
if (DrawLine)
{
if (