You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The script begins by loading two .NET Framework classes: **System.Drawing** and **System.Windows.Forms**. You then start a new instance of the .NET Framework class **Windows.Forms.Form**; that provides a blank form or window to which you can start adding controls.
58
+
The script begins by loading two .NET Framework classes: **System.Drawing** and **System.Windows.Forms**.
59
+
You then start a new instance of the .NET Framework class **Windows.Forms.Form**; that provides a blank form or window to which you can start adding controls.
After you create an instance of the Form class, assign values to three properties of this class.
70
+
This example assigns values to four properties of this class by using the **Property** property and hashtable.
64
71
65
-
-**Text.** This becomes the title of the window.
72
+
1.**StartPosition**:
73
+
If you don’t add this property, Windows selects a location when the form is opened.
74
+
By setting this property to **CenterScreen**, you’re automatically displaying the form in the middle of the screen each time it loads.
66
75
67
-
-**Size.** This is the size of the form, in pixels. The preceding script creates a form that’s 243 pixels wide by 230 pixels tall.
76
+
2.**Size**:
77
+
This is the size of the form, in pixels.
78
+
The preceding script creates a form that’s 243 pixels wide by 230 pixels tall.
68
79
69
-
-**StartingPosition.** This optional property is set to **CenterScreen** in the preceding script. If you don’t add this property, Windows selects a location when the form is opened. By setting the **StartingPosition** to **CenterScreen**, you’re automatically displaying the form in the middle of the screen each time it loads.
80
+
3.**Text**:
81
+
This becomes the title of the window.
70
82
71
-
```powershell
72
-
$form.Text = 'Select a Date'
73
-
$form.Size = New-Object Drawing.Size @(243,230)
74
-
$form.StartPosition = 'CenterScreen'
75
-
```
83
+
4.**Topmost**:
84
+
By setting this property to `$true`, you can force the window to open atop other open windows and dialog boxes.
76
85
77
-
Next, create and then add a calendar control in your form. In this example, the current day is not highlighted or circled. Users can select only one day on the calendar at one time.
86
+
Next, create and then add a calendar control in your form.
87
+
In this example, the current day is not highlighted or circled.
88
+
Users can select only one day on the calendar at one time.
Next, create an **OK** button for your form. Specify the size and behavior of the **OK** button. In this example, the button position is 165 pixels from the form’s top edge, and 38 pixels from the left edge. The button height is 23 pixels, while the button length is 75 pixels. The script uses predefined Windows Forms types to determine the button behaviors.
98
+
Next, create an **OK** button for your form.
99
+
Specify the size and behavior of the **OK** button.
100
+
In this example, the button position is 165 pixels from the form’s top edge, and 38 pixels from the left edge.
101
+
The button height is 23 pixels, while the button length is 75 pixels.
102
+
The script uses predefined Windows Forms types to determine the button behaviors.
Set the **Topmost** property to **$true** to force the window to open atop other open windows and dialog boxes.
111
-
112
-
```powershell
113
-
$form.Topmost = $true
114
-
```
115
-
116
129
Add the following line of code to display the form in Windows.
117
130
118
131
```powershell
119
132
$result = $form.ShowDialog()
120
133
```
121
134
122
-
Finally, the code inside the **If** block instructs Windows what to do with the form after users select a day on the calendar, and then click the **OK** button or press the **Enter** key. Windows PowerShell displays the selected date to users.
135
+
Finally, the code inside the `if` block instructs Windows what to do with the form after users select a day on the calendar, and then click the **OK** button or press the **Enter** key.
136
+
Windows PowerShell displays the selected date to users.
123
137
124
138
```powershell
125
-
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
126
-
{
139
+
if ($result -eq [Windows.Forms.DialogResult]::OK) {
0 commit comments