明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 8349|回复: 13

[界面] PaletteSet

[复制链接]
发表于 2010-12-29 15:06 | 显示全部楼层 |阅读模式
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");
            }
        }
    }
}
帮忙看下红色标记的哪里错了?

发表于 2010-12-29 16:42 | 显示全部楼层
本帖最后由 雪山飞狐_lzh 于 2010-12-29 16:45 编辑

报的什么错?你的Cad版本?
另外,你可以看下ObjectArxSdk下dotNet的例子DockingPalette
 楼主| 发表于 2010-12-29 22:56 | 显示全部楼层
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


就是这个
发表于 2010-12-29 22:57 | 显示全部楼层
添加引用->PresentationCore
发表于 2010-12-30 10:19 | 显示全部楼层
你似乎想在一个非模式窗口中显示paletteset?好像不是这么做吧
 楼主| 发表于 2010-12-30 10:54 | 显示全部楼层
是无模式窗体,我只是写了个创建的
 楼主| 发表于 2010-12-30 11:30 | 显示全部楼层
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;
            }
        }
    }

    }

全部的代码,但是出现了问题无法取出控件中的值
 楼主| 发表于 2010-12-30 11:31 | 显示全部楼层
能不能帮我看下什么原因.初学者
发表于 2010-12-30 13:09 | 显示全部楼层
不是用窗体的,而是用户控件
 楼主| 发表于 2010-12-30 14:47 | 显示全部楼层
我是用的用户控件
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-19 12:07 , Processed in 0.180154 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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