在文档窗口中添加控件的简单原型
下面的代码是简单的原型,只是把怎么做的实现技术罗列在一起,如果要真正实现还是要费点手脚:)响铃版主有更完整的版本,让我们拭目以待
static extern IntPtr SetParent(IntPtr child, IntPtr newParent);
static System.Windows.Forms.Button button1 = new System.Windows.Forms.Button();
public static void ShowMe()
{
if (button1 == null)
{
button1 = new System.Windows.Forms.Button();
}
button1.Location = new System.Drawing.Point(31, 29);
button1.Name = "button1";
button1.Size = new System.Drawing.Size(87, 35);
button1.TabIndex = 0;
button1.Text = "button1";
button1.UseVisualStyleBackColor = true;
button1.Click += new EventHandler(button1_Click);
Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
SetParent(button1.Handle, doc.Window.Handle);
}
static void button1_Click(object sender, EventArgs e)
{
button1.Dispose();
button1 = null;
}
public class Class1
{
static extern IntPtr SetParent(IntPtr child, IntPtr newParent);
static UcSysMenu panSysMenu;
public void loadSysMenu()
{
DocumentCollection DocCollection = Application.DocumentManager;
//文档创建事件
DocCollection.DocumentCreated += new DocumentCollectionEventHandler(DocCollection_DocumentCreated);
foreach (Document doc in DocCollection)
{
panSysMenu = new UcSysMenu();
panSysMenu.Location = new System.Drawing.Point(31, 29);
SetParent(panSysMenu.Handle, doc.Window.Handle);
}
}
void DocCollection_DocumentCreated(object sender, DocumentCollectionEventArgs e)
{
panSysMenu = new UcSysMenu();
panSysMenu.Location = new System.Drawing.Point(31, 29);
SetParent(panSysMenu.Handle, Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Window.Handle);
}
}我的无非就是给加上了一个文档创建事件而已,这样可以实现每个CAD文档都能添加一样的控件.
拜读2位的大作,感触良多...谢谢! 请教二位老大,如何能将这个按钮添加到cad左下角的坐标区呢?
我试了这个,貌似不对
SetParent(button1.Handle, doc.StatusBar.Window.Handle);
谢谢!
拜读2位的大作,感触良多...谢谢! 学习了,先码上,以后会用到 很好的思路啊 比如编辑文字可以用
页:
[1]