控制“应用程序”窗口的功能使开发人员能够灵活地创建有效和智能的应用程序。有时,您的应用程序适合最小化 AutoCAD 窗口,也许当您的代码在另一个应用程序(如 Microsoft® Excel®)中执行工作时。此外,在执行诸如提示用户输入等任务之前,您通常需要验证 AutoCAD 窗口的状态。 使用在 Application 对象上找到的方法和属性,可以更改 Application 窗口的位置、大小和可见性。还可以使用该属性来最小化、最大化和检查“应用程序”窗口的当前状态。WindowState “应用程序”窗口的位置和大小本示例使用 and 属性将 AutoCAD 应用程序窗口定位在屏幕的左上角,并将其调整为 400 像素宽 x 400 像素高。LocationSize 注意:下面的示例要求对项目引用 PresentationCore (PresentationCore.dll) 库。使用“添加引用”对话框,然后从“.NET”选项卡中选择“PresentationCore”。
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”选项卡中选择“PresentationCore”。
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 代码参考Sub MinMaxApplicationWindow()
'' Minimize the Application window
ThisDrawing.Application.WindowState = acMin
MsgBox "Minimized"
'' Maximize the Application window
ThisDrawing.Application.WindowState = acMax
MsgBox "Maximized"
End Sub
查找“应用程序”窗口的当前状态此示例查询“应用程序”窗口的状态,并在消息框中向用户显示该状态。 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 代码参考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
使“应用程序”窗口不可见和可见以下代码使用该特性使 AutoCAD 应用程序窗口不可见,然后再次可见。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 苏公网安备32011402011833)
GMT+8, 2025-10-29 09:50
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.