明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4926|回复: 6

[界面] 在文档窗口中添加控件的简单原型

  [复制链接]
发表于 2009-11-15 11:03 | 显示全部楼层 |阅读模式
下面的代码是简单的原型,只是把怎么做的实现技术罗列在一起,如果要真正实现还是要费点手脚:)
响铃版主有更完整的版本,让我们拭目以待
  1.         [DllImport("user32.dll")]
  2.         static extern IntPtr SetParent(IntPtr child, IntPtr newParent);
  3.         static System.Windows.Forms.Button button1 = new System.Windows.Forms.Button();
  4.         [CommandMethod("sab")]
  5.         public static void ShowMe()
  6.         {
  7.             if (button1 == null)
  8.             {
  9.                 button1 = new System.Windows.Forms.Button();
  10.             }
  11.             button1.Location = new System.Drawing.Point(31, 29);
  12.             button1.Name = "button1";
  13.             button1.Size = new System.Drawing.Size(87, 35);
  14.             button1.TabIndex = 0;
  15.             button1.Text = "button1";
  16.             button1.UseVisualStyleBackColor = true;
  17.             button1.Click += new EventHandler(button1_Click);
  18.             Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  19.             
  20.             SetParent(button1.Handle, doc.Window.Handle);
  21.         }
  22.         static void button1_Click(object sender, EventArgs e)
  23.         {
  24.             button1.Dispose();
  25.             button1 = null;
  26.         }
复制代码

评分

参与人数 1威望 +1 明经币 +2 金钱 +20 贡献 +5 激情 +5 收起 理由
lzx838 + 1 + 2 + 20 + 5 + 5 【精华】好程序

查看全部评分

发表于 2009-11-17 09:05 | 显示全部楼层
  1.     public class Class1
  2.     {
  3.         [DllImport("user32.dll")]
  4.         static extern IntPtr SetParent(IntPtr child, IntPtr newParent);
  5.         static UcSysMenu panSysMenu;
  6.         [Autodesk.AutoCAD.Runtime.CommandMethod("MyMenu")]
  7.         public void loadSysMenu()
  8.         {
  9.             DocumentCollection DocCollection = Application.DocumentManager;
  10.             //文档创建事件
  11.             DocCollection.DocumentCreated += new DocumentCollectionEventHandler(DocCollection_DocumentCreated);
  12.             foreach (Document doc in DocCollection)
  13.             {
  14.                 panSysMenu = new UcSysMenu();
  15.                 panSysMenu.Location = new System.Drawing.Point(31, 29);
  16.                 SetParent(panSysMenu.Handle, doc.Window.Handle);
  17.             }
  18.         }
  19.         void DocCollection_DocumentCreated(object sender, DocumentCollectionEventArgs e)
  20.         {
  21.             panSysMenu = new UcSysMenu();
  22.             panSysMenu.Location = new System.Drawing.Point(31, 29);
  23.             SetParent(panSysMenu.Handle, Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Window.Handle);
  24.         }
  25.     }
复制代码
我的无非就是给加上了一个文档创建事件而已,这样可以实现每个CAD文档都能添加一样的控件.
发表于 2015-5-15 13:47 | 显示全部楼层
拜读2位的大作,感触良多...谢谢!
发表于 2017-8-16 23:55 | 显示全部楼层
请教二位老大,如何能将这个按钮添加到cad左下角的坐标区呢?
我试了这个,貌似不对
SetParent(button1.Handle, doc.StatusBar.Window.Handle);
谢谢!
发表于 2020-3-14 20:50 | 显示全部楼层

拜读2位的大作,感触良多...谢谢!
发表于 2020-4-1 09:51 | 显示全部楼层
学习了,先码上,以后会用到
发表于 2021-7-28 21:14 来自手机 | 显示全部楼层
很好的思路啊 比如编辑文字可以用
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-20 12:31 , Processed in 0.153315 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表