EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 688|回复: 0
打印 上一主题 下一主题

[资料] 控制AutoCAD环境(一) 控制应用程序窗口

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-8 16:12:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Control the AutoCAD Environment
控制AutoCAD环境
This chapter describes the fundamentals for developing an application that runs in-process with AutoCAD. It explains many of the concepts to control and work effectively with the AutoCAD environment.
本章是开发AutoCAD进程内应用程序的基础,将学习到控制和使用AutoCAD环境的许多概念。

Topics in this section
本章主要内容


Control the Application Window
控制应用程序窗口

Control the Drawing Windows
控制图形窗口

Create, Open, Save, and Close Drawings
创建、打开、保存和关闭图形

Lock and Unlock a Document
锁定和解锁文档

Set AutoCAD Preferences
设置AutoCAD选项

Set and Return System Variables
设置和返回系统变量

Draw with Precision
精确制图

Prompt for User Input
提示用户输入

Access the AutoCAD Command Line
访问AutoCAD命令行


Control the Application Window
控制应用程序窗口
The ability to control the Application window allows developers the flexibility to create effective and intelligent applications. There will be times when it is appropriate for your application to minimize the AutoCAD window, perhaps while your code is performing work in another application such as Microsoft® Excel®. Additionally, you will often want to verify the state of the AutoCAD window before performing such tasks as prompting for input from the user.
控制AutoCAD应用程序窗口的能力让开发人员可以灵活地创建高效智能的应用程序。比如有时我们需要在程序中适时地最小化AutoCAD窗口,也许此时我们的代码正在使用其他应用程序如Excel处理任务。又比如,我们在执行像提示用户输入这样的任务前,经常需要确认AutoCAD窗口的状态。
Using methods and properties found on the Application object, you can change the position, size, and visibility of the Application window. You can also use the WindowState property to minimize, maximize, and check the current state of the Application window.
使用Application对象的方法和属性,我们可以改变Application窗口的位置、大小及可见性,还可以用WindowState属性来最小化、最大化Application窗口,以及检查Application窗口的当前状态等。
Position and size the Application window 设置应用程序窗口位置和大小

This example uses the Location and Size properties to position the AutoCAD Application window in the upper-left corner of the screen and size it to 400 pixels wide by 400 pixels high.
本例使用Location属性和Size属性将AutoCAD应用窗口定位于屏幕左上角,并将窗口大小设置为400×400像素。
Note The following examples require that the PresentationCore (PresentationCore.dll) library to be referenced to the project. Use the Add Reference dialog box and select PresentationCore from the .NET tab.
注意:下列示例需要在项目中引用PresentationCore库(PresentationCore.dll)。从添加引用对话框的.NET选项页中选PresentationCore即可。
VB.NET
Imports System.Drawing
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices

<CommandMethod("PositionApplicationWindow")> _
Public Sub PositionApplicationWindow()

'' Set the position of the Application window

Dim ptApp As Point = New Point(0, 0)

Application.MainWindow.Location = ptApp


'' Set the size of the Application window

Dim szApp As Size = New Size(400, 400)

Application.MainWindow.Size = szApp
End Sub
C#
using System.Drawing;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;

[CommandMethod("PositionApplicationWindow")]
public static void PositionApplicationWindow()
{

// Set the position of the Application window

//
设置应用程序窗口位置

Point ptApp = new Point(0, 0);

Application.MainWindow.Location = ptApp;


// Set the size of the Application window

//
设置应用程序窗口大小

Size szApp = new Size(400, 400);

Application.MainWindow.Size = szApp;
}

VBA/ActiveX Code Reference
Sub PositionApplicationWindow()

'' Set the position of the Application window

ThisDrawing.Application.WindowTop = 0

ThisDrawing.Application.WindowLeft = 0


'' Set the size of the Application window

ThisDrawing.Application.width = 400

ThisDrawing.Application.height = 400
End Sub
Minimize and maximize the Application window 最小化和最大化应用程序窗口

Note The following examples require that the PresentationCore (PresentationCore.dll) library to be referenced to the project. Use the Add Reference dialog box and select PresentationCore from the .NET tab.
注意:下列示例需要在项目中引用PresentationCore库(PresentationCore.dll)。从添加引用对话框的.NET选项页中选PresentationCore即可。
VB.NET
Imports System.Drawing
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Windows

<CommandMethod("MinMaxApplicationWindow")> _
Sub MinMaxApplicationWindow()

'' Minimize the Application window

Application.MainWindow.WindowState = Window.State.Minimized

MsgBox("Minimized", MsgBoxStyle.SystemModal, "MinMax")


'' Maximize the Application window

Application.MainWindow.WindowState = Window.State.Maximized

MsgBox("Maximized", MsgBoxStyle.SystemModal, "MinMax")
End Sub
C#
using System.Drawing;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Windows;

[CommandMethod("MinMaxApplicationWindow")]
public static void MinMaxApplicationWindow()
{

// Minimize the Application window
最小化应用程序窗口

Application.MainWindow.WindowState = Window.State.Minimized;

System.Windows.Forms.MessageBox.Show("Minimized", "MinMax",

System.Windows.Forms.MessageBoxButtons.OK,

System.Windows.Forms.MessageBoxIcon.None,

System.Windows.Forms.MessageBoxDefaultButton.Button1,

System.Windows.Forms.MessageBoxOptions.ServiceNotification);


// Maximize the Application window
最大化应用程序窗口

Application.MainWindow.WindowState = Window.State.Maximized;

System.Windows.Forms.MessageBox.Show("Maximized", "MinMax");
}

VBA/ActiveX Code Reference
Sub MinMaxApplicationWindow()

'' Minimize the Application window

ThisDrawing.Application.WindowState = acMin

MsgBox "Minimized"


'' Maximize the Application window

ThisDrawing.Application.WindowState = acMax

MsgBox "Maximized"
End Sub
Find the current state of the Application window 获取应用程序窗口当前状态

This example queries the state of the Application window and displays the state in a message box to the user.
本示例查询应用程序窗口的状态并将其显示出来。
VB.NET
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Windows

<CommandMethod("CurrentWindowState")> _
Public Sub CurrentWindowState()

System.Windows.Forms.MessageBox.Show("The application window is " + _

Application.MainWindow.WindowState.ToString(), _

"Window State")
End Sub
C#
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Windows;

[CommandMethod("CurrentWindowState")]
public static void CurrentWindowState()
{

System.Windows.Forms.MessageBox.Show("The application window is " +

Application.MainWindow.WindowState.ToString(),

"Window State");
}

VBA/ActiveX Code Reference
Sub CurrentWindowState()

Dim CurrWindowState As Integer

Dim msg As String

CurrWindowState = ThisDrawing.Application.WindowState

msg = Choose(CurrWindowState, "Normal", _

"Minimized", "Maximized")

MsgBox "The application window is " + msg
End Sub
Make the Application window invisible and visible 使应用程序窗口不可见和可见

The following code uses the Visible property to make the AutoCAD application invisible and then visible again.
下列代码用Visible属性让AutoCAD应用程序窗口不可见,然后再可见。
VB.NET
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Windows

<CommandMethod("HideWindowState")> _
Public Sub HideWindowState()

'' Hide the Application window

Application.MainWindow.Visible = False

MsgBox("Invisible", MsgBoxStyle.SystemModal, "Show/Hide")


'' Show the Application window

Application.MainWindow.Visible = True

MsgBox("Visible", MsgBoxStyle.SystemModal, "Show/Hide")
End Sub
C#
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Windows;

[CommandMethod("HideWindowState")]
public static void HideWindowState()
{

// Hide the Application window
隐藏应用程序窗口

Application.MainWindow.Visible = false;

System.Windows.Forms.MessageBox.Show("Invisible", "Show/Hide");


// Show the Application window
显示应用程序窗口

Application.MainWindow.Visible = true;

System.Windows.Forms.MessageBox.Show("Visible", "Show/Hide");
}

VBA/ActiveX Code Reference
Sub HideWindowState()

'' Hide the Application window

ThisDrawing.Application.Visible = False

MsgBox "Invisible"


'' Show the Application window

ThisDrawing.Application.Visible = True

MsgBox "Visible"
End Sub

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对

相关帖子

工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-23 13:44

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

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