控制“应用程序”窗口的功能使开发人员能够灵活地创建有效且智能的应用程序。有时,应用程序适合最小化AutoCAD窗口,也许当您的代码在另一个应用程序(如Microsoft®Excel®)中执行工作时。此外,在执行提示用户输入等任务之前,您通常需要验证 AutoCAD 窗口的状态。 使用在应用程序对象上找到的方法和属性,可以更改应用程序窗口的位置、大小和可见性。还可以使用该属性来最小化、最大化和检查“应用程序”窗口的当前状态。WindowState 定位和调整应用程序窗口的大小本示例使用属性将 AutoCAD 应用程序窗口定位在屏幕的左上角,并将其大小调整为 400 像素宽 x 400 像素高。LocationSize 注意:以下示例要求将 PresentationCore (PresentationCore.dll) 库引用到项目。使用“添加引用”对话框,然后从“.NET”选项卡中选择“演示核心”。
VB.NETImports 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 System.Windows.Point = New System.Windows.Point(0, 0) Autodesk.AutoCAD.ApplicationServices.Core.Application.MainWindow.DeviceIndependentLocation = ptApp '' Set the size of the Application window Dim szApp As System.Windows.Size = New System.Windows.Size(400, 400) Autodesk.AutoCAD.ApplicationServices.Core.Application.MainWindow.DeviceIndependentSize = 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 System.Windows.Point ptApp = new System.Windows.Point(0, 0); Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.DeviceIndependentLocation = ptApp; // Set the size of the Application window System.Windows.Size szApp = new System.Windows.Size(400, 400); Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.DeviceIndependentSize = szApp; } VBA/ActiveX 代码参考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 最小化和最大化应用程序窗口注意:以下示例要求将 PresentationCore (PresentationCore.dll) 库引用到项目。使用“添加引用”对话框,然后从“.NET”选项卡中选择“演示核心”。
VB.NETImports System.Drawing Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Windows <CommandMethod("MinMaxApplicationWindow")> _ Public 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 ReferenceSub 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 windowThis example queries the state of the Application window and displays the state in a message box to the user. VB.NETImports 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 ReferenceSub 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 visibleThe following code uses the property to make the AutoCAD application window invisible and then visible again. Visible VB.NETImports 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 代码参考Sub HideWindowState() '' Hide the Application window ThisDrawing.Application.Visible = False MsgBox "Invisible" '' Show the Application window ThisDrawing.Application.Visible = True MsgBox "Visible" End Sub |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )
GMT+8, 2024-6-5 00:07
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.