gisoracle

View Post

利用C#进行AutoCAD的二次开发 颜色和样式

利用C#进行AutoCAD的二次开发(四)(转自明经通道)

(2010-10-06 19:51:32)
                              使用通用对话框
      看了本站出的“AutoCAD VBA 开发精彩实例教程”以后,深有启发。但书中用到通用对话框时,总是调用windows api函数,我一看就头大了。想到C#可以调用通用对话框,因此试验了一下,没想到在C#中可以非常容易地解决这个问题,下面就把我的做法给写出来。
      本文的例子是调用颜色对话框,对于其他通用对话框做法是一样的。但由于要使用到AutoCAD2004新增加的TrueColor属性,因此,本文所举的例子只能用于AutoCAD2004,对于其他通用对话框(如文件对话框),则可以使用其他版本的AutoCAD。
要求:
       会用C#编程
       读过我写的“利用C#进行AutoCAD的二次开发“(在明经通道中有)
开始:
      在visual studio.net中新建一C#控制台程序,在引用选项卡中添加下列类库:
               interop.AutoCAD.dll
               AcadExample.dll
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using AutoCAD;
using AcadExample;
namespace WindowsApplication3
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;
  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();
   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }
  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }
  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.button1 = new System.Windows.Forms.Button();
   this.SuspendLayout();
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(96, 112);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(64, 32);
   this.button1.TabIndex = 0;
   this.button1.Text = "确定";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(280, 213);
   this.Controls.Add(this.button1);
   this.Name = "Form1";
   this.Text = "Form1";
   this.ResumeLayout(false);
  }
  #endregion
  /// <summary>
  /// 应用程序的主入口点。

分类:

技术点:

相关文章: