PaletteSet
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.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Runtime;
namespace Palette
{
public partial class ModelessForm : UserControl
{
private Autodesk.AutoCAD.Windows.PaletteSet palSet;
public ModelessForm()
{
InitializeComponent();
}
public void AddPalette()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
try
{
if (palSet == null)
{
palSet = new PaletteSet("My Palette");
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("My Palette",ModelessForm);
palSet.Visible = true;
}
}
catch {
ed.WriteMessage("Create panel set wrong");
}
}
}
}
帮忙看下红色标记的哪里错了?
本帖最后由 雪山飞狐_lzh 于 2010-12-29 16:45 编辑
报的什么错?你的Cad版本?
另外,你可以看下ObjectArxSdk下dotNet的例子DockingPalette
Error 1 The type 'System.Windows.Interop.IWin32Window' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. E:\learning Example\AutoCAD.NET API\CeateOpject\Palette\Palette\ModelessForm.cs 20 53 Palette
就是这个 添加引用->PresentationCore 你似乎想在一个非模式窗口中显示paletteset?好像不是这么做吧 是无模式窗体,我只是写了个创建的 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
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, 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;
}
}
}
}
全部的代码,但是出现了问题无法取出控件中的值 能不能帮我看下什么原因.初学者 不是用窗体的,而是用户控件 我是用的用户控件
页:
[1]
2