确认和取消按钮事件
<p>请教各位高手帮助写个简单的按钮事例!!!<br/> 在C#中新建一个类(.dll),同时再添加一个窗体(如下图片),最后点[确认]按钮就可以执行以下程序在CAD中指定位置画一个圆,如果点[取消]按钮,则直接退出窗体就不用执行以下程序。(以下是画圆的代码)</p><p><br/><br/> </p> 以下是画圆的代码:(请帮助增加一个如同以上窗体中的[确认]按钮和[取消]按钮的动作)
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
namespace ClassLibrary
{
public class YdsClass
{
static public void test()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptPointOptions p = new PromptPointOptions("");
p.Message = "请选取圆心!";
PromptPointResult result = ed.GetPoint(p);
if (result.Status.ToString() == "OK")
{
Point3d centerPoint = result.Value;
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acDoc.TransactionManager.StartTransaction())
{
BlockTable acTab = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec = acTrans.GetObject(acTab, OpenMode.ForWrite) as BlockTableRecord;
Circle newCircle = new Circle();
newCircle.SetDatabaseDefaults();
newCircle.Center = centerPoint;
newCircle.Radius = 10;
acBlkTblRec.AppendEntity(newCircle);
acTrans.AddNewlyCreatedDBObject(newCircle, true);
acTrans.Commit();
}
}
}
}
}
在窗体上设置下面的属性:
button1.DialogResult = DialogResult.OK;
this.AcceptButton = button1;
this.CancelButton = button2;
button1添加事件:
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
你的代码写的有点奇怪,哎
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
namespace ClassLibrary3
{
public class YdsClass
{
static public void test()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Form1 frm = new Form1();
var res = Application.ShowModalDialog(frm);
if (res == System.Windows.Forms.DialogResult.Cancel)
{
ed.WriteMessage("\n命令被取消!");
return;
}
PromptPointOptions p = new PromptPointOptions("");
p.Message = "\n请选取圆心:";
PromptPointResult result = ed.GetPoint(p);
if (result.Status == PromptStatus.OK)
{
Point3d centerPoint = result.Value;
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acDoc.TransactionManager.StartTransaction())
{
BlockTable acTab = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec = acTrans.GetObject(acTab, OpenMode.ForWrite) as BlockTableRecord;
Circle newCircle = new Circle();
newCircle.SetDatabaseDefaults();
newCircle.Center = centerPoint;
newCircle.Radius = 10;
acBlkTblRec.AppendEntity(newCircle);
acTrans.AddNewlyCreatedDBObject(newCircle, true);
acTrans.Commit();
}
}
}
}
}
<p>狐哥</p>
<p>你可否在以上的程序上再帮我补上这两个按钮的动作啊</p> <p>还是把工程上传吧,汗</p> <p>狐哥</p>
<p>非常感谢你的再次帮助...我会去慢慢的理解你的程序...这对于象我这样还没有入门的初学者来说确实很难阿...</p>
页:
[1]