利用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>