アプリケーション ウィンドウをコントロールできるので、開発者は効果的でインテリジェントなアプリケーションを柔軟に作成することができます。アプリケーションで、コードが他のアプリケーション(たとえば、Microsoft® Excel®)の作業を実行している間、AutoCAD ウィンドウを最小化する方がよい場合があります。また、ユーザからの入力を要求するプロンプトなどのタスクを実行する前に AutoCAD ウィンドウの状態を確認することが必要となる場合があります。
Application オブジェクトにあるメソッドとプロパティを使うと、アプリケーション ウィンドウの位置とサイズ、およびウィンドウの表示/非表示を変更することができます。また、WindowState プロパティを使用すると、アプリケーション ウィンドウを最小化または最大化したり、アプリケーション ウィンドウの現在の状態を確認することができます。
以下の例では、Location および Size プロパティを使って、AutoCAD アプリケーション ウィンドウをスクリーンの左上コーナーに配置し、サイズを幅 400 ×高さ 400 ピクセルに変更します。
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 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
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;
}
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
Imports 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
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");
}
Sub MinMaxApplicationWindow()
'' Minimize the Application window
ThisDrawing.Application.WindowState = acMin
MsgBox "Minimized"
'' Maximize the Application window
ThisDrawing.Application.WindowState = acMax
MsgBox "Maximized"
End Sub
以下の例では、アプリケーション ウィンドウの現在の状態を問い合わせ、ユーザにメッセージ ボックスで通知します。
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
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");
}
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
次のコードは、Visible プロパティを使用して AutoCAD アプリケーション ウィンドウを非表示にしてから再び表示します。
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
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");
}
Sub HideWindowState()
'' Hide the Application window
ThisDrawing.Application.Visible = False
MsgBox "Invisible"
'' Show the Application window
ThisDrawing.Application.Visible = True
MsgBox "Visible"
End Sub