- 积分
- 155
- 明经币
- 个
- 注册时间
- 2010-12-27
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2010-12-30 11:30:51
|
显示全部楼层
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsSystem;
using System.IO;
namespace palette2
{
public partial class ModelessForm : UserControl
{
private Autodesk.AutoCAD.Windows.PaletteSet palSet;
public ModelessForm()
{
InitializeComponent();
label5.MouseMove += new System.Windows.Forms.MouseEventHandler(label5_MouseMove);
}
//createPaletteSet
[CommandMethod("CreatePaletteSet")]
public void AddPalette()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
try
{
if (palSet == null)
{
palSet = new PaletteSet("MyPalette");
palSet.Style = PaletteSetStyles.ShowTabForSingle;
palSet.Style = PaletteSetStyles.NameEditable;
palSet.Style = PaletteSetStyles.ShowPropertiesMenu;
palSet.Style = PaletteSetStyles.ShowAutoHideButton;
palSet.Style = PaletteSetStyles.ShowCloseButton;
palSet.Opacity = 90;
palSet.MinimumSize = new System.Drawing.Size(300, 300);
System.Windows.Forms.UserControl myPageCtrl = new ModelessForm();
palSet.Add("MyPalette", myPageCtrl);
palSet.Visible = true;
}
}
catch
{
ed.WriteMessage("Create panel set wrong");
}
}
/// <summary>
/// click movent
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void label5_MouseMove(object sender, MouseEventArgs e)
{
if (System.Windows.Forms.Control.MouseButtons == System.Windows.Forms.MouseButtons.Left)
{
//star DropTarge
Autodesk.AutoCAD.ApplicationServices.Application.DoDragDrop(this, this, System.Windows.Forms.DragDropEffects.All, new MyDropTarget());
}
}
}
public class MyDropTarget : Autodesk.AutoCAD.Windows.DropTarget
{
//
public override void OnDrop(DragEventArgs e)
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
try
{
Point3d pt = ed.PointToWorld(new Point(e.X, e.Y));
using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
{
//get Data
ModelessForm ctrl = (ModelessForm)e.Data.GetData(typeof(ModelessForm)); //creat Entity
Utility.CreateEmployee();
}
}
catch
{
ed.WriteMessage("Create fail");
}
}
}
public class Utility
{
public static ObjectId CreateEmployee(String name, String division, Double salary, Point3d pos)
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
// create circle
Circle cir = new Circle();
cir.Center = pos;
cir.Radius = 100;
cir.ColorIndex = 1;
btr.AppendEntity(cir);
trans.AddNewlyCreatedDBObject(cir, true);
//create record
Xrecord xRec = new Xrecord();
xRec.Data = new ResultBuffer(
new TypedValue((int)DxfCode.Text, name),
new TypedValue((int)DxfCode.Real, salary),
new TypedValue((int)DxfCode.Text, division));
cir.CreateExtensionDictionary();
DBDictionary brExtDict = (DBDictionary)trans.GetObject(cir.ExtensionDictionary, OpenMode.ForWrite, false);
brExtDict.SetAt("EmpInfor", xRec);
trans.AddNewlyCreatedDBObject(xRec, true);
trans.Commit();
//
return cir.ObjectId;
}
}
}
}
全部的代码,但是出现了问题无法取出控件中的值 |
|