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