{"id":2960,"date":"2011-06-01T13:23:21","date_gmt":"2011-06-01T21:23:21","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=2960"},"modified":"2016-02-12T16:15:58","modified_gmt":"2016-02-13T00:15:58","slug":"primalforms-2011-spotlight-on-the-form-control","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2011\/06\/01\/primalforms-2011-spotlight-on-the-form-control\/","title":{"rendered":"Spotlight on the Form Control"},"content":{"rendered":"<p>The <em><a href=\"https:\/\/www.sapien.com\/blog\/topics\/spotlight-on-controls\/\" target=\"_blank\">Spotlight on Controls<\/a><\/em> series describes the <i>controls<\/i>, that is, the objects in the System.Windows.Forms namespace, so you can use them effectively when building GUI apps in PowerShell Studio and PrimalScript.<\/p>\n<p>Each post focuses on one control and lists its most important properties, methods, and events, including the default event that PowerShell Studio adds to your script when you double-click the control. The posts include many examples written in Windows PowerShell, so you can use them right away.<\/p>\n<p>Read more: <a href=\"https:\/\/www.sapien.com\/blog\/2011\/06\/01\/primalforms-2011-spotlight-on-controls\/\">Shared properties of GUI app controls<\/a><\/p>\n<p>This post describes the Form control.<\/p>\n<h1>Form Control [System.Windows.Forms.Form]<\/h1>\n<p>The Form control represents the application window that contains the other\u00a0controls.<\/p>\n<ul>\n<li>MSDN Page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.form(v=vs.110).aspx\" target=\"_blank\">System.Windows.Forms.Form<\/a><\/li>\n<li>Default Event: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.form.load(v=vs.110).aspx\" target=\"_blank\">Load<\/a><\/li>\n<\/ul>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-08.53.50.png\" rel=\"attachment wp-att-11169\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-11169\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-08.53.50.png\" alt=\"Screenshot 2016-02-11 08.53.50\" width=\"296\" height=\"168\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-08.53.50.png 329w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-08.53.50-300x171.png 300w\" sizes=\"auto, (max-width: 296px) 100vw, 296px\" \/><\/a><\/p>\n<h1>Important properties of the Form object<\/h1>\n<ul>\n<li><a href=\"#Text\">Text<\/a><\/li>\n<li><a href=\"#FormBorderStyle\">FormBorderStyle<\/a><\/li>\n<li><a href=\"#Icon\">Icon<\/a><\/li>\n<li><a href=\"#StartPosition\">StartPosition<\/a><\/li>\n<li><a href=\"#WindowState\">WindowState<\/a><\/li>\n<li><a href=\"#ControlBox\">ControlBox<\/a><\/li>\n<li><a href=\"#MinimizeBox\">MinimizeBox<\/a><\/li>\n<li><a href=\"#MaximizeBox\">MaximizeBox<\/a><\/li>\n<li><a href=\"#AcceptButton\">AcceptButton<\/a><\/li>\n<li><a href=\"#CancelButton\">CancelButton<\/a><\/li>\n<li><a href=\"#BackgroundImage\">BackgroundImage<\/a><\/li>\n<li><a href=\"#BackgroundImageLayout\">BackgroundImageLayout<\/a><\/li>\n<\/ul>\n<h1>Important events of the Form object<\/h1>\n<ul>\n<li><a href=\"#Load\">Load<\/a><\/li>\n<li><a href=\"#FormClosing\">FormClosing<\/a><\/li>\n<\/ul>\n<h1>Important methods of the Form object<\/h1>\n<ul>\n<li><a href=\"#Close\">Close<\/a><\/li>\n<\/ul>\n<p><a name=\"Text\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>Text property:\u00a0 Sets the form title<\/h1>\n<p>Use the Text property to get or change the title of the form.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.string(v=vs.110).aspx\" target=\"_blank\">System.String<\/a><br \/>\n<b>Default value<\/b>: Form<br \/>\nFor example, the value of the Text property of this form is &#8220;Form.&#8221;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-08.53.50.png\" rel=\"attachment wp-att-11169\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-11169\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-08.53.50.png\" alt=\"Screenshot 2016-02-11 08.53.50\" width=\"296\" height=\"168\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-08.53.50.png 329w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-08.53.50-300x171.png 300w\" sizes=\"auto, (max-width: 296px) 100vw, 296px\" \/><\/a><\/p>\n<p>To change the form title, in the Properties pane, change the value of the <strong>Text<\/strong> property of the form.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.12.22.png\" rel=\"attachment wp-att-11170\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-11170\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.12.22.png\" alt=\"Screenshot 2016-02-11 14.12.22\" width=\"318\" height=\"220\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.12.22.png 357w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.12.22-300x208.png 300w\" sizes=\"auto, (max-width: 318px) 100vw, 318px\" \/><\/a><\/p>\n<p>Or, set the value of the <strong>Text<\/strong> property of the form in the script.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.12.22-1.png\" rel=\"attachment wp-att-11171\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11171\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.12.22-1.png\" alt=\"Screenshot 2016-02-11 14.12.22-1\" width=\"378\" height=\"110\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.12.22-1.png 378w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.12.22-1-300x87.png 300w\" sizes=\"auto, (max-width: 378px) 100vw, 378px\" \/><\/a><\/p>\n<p>Here&#8217;s the result.<\/p>\n<p style=\"padding-left: 30px;\">\u00a0<a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.25.16.png\" rel=\"attachment wp-att-11172\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11172\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.25.16.png\" alt=\"Screenshot 2016-02-11 14.25.16\" width=\"332\" height=\"180\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.25.16.png 332w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-14.25.16-300x163.png 300w\" sizes=\"auto, (max-width: 332px) 100vw, 332px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Note: When you change the Text property value of a form (or other control), PowerShell Studio and PrimalScript automatically rename the variable that stores the form object. For example, if you set the Text property of the form to &#8220;Get Process,&#8221; the variable name is changed to $formGetProcess. To disable this feature, in Options\/Designer, uncheck <strong>Sync control names with text<\/strong>.<\/p>\n<p><a name=\"FormBorderStyle\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>FormBorderStyle property: Appearance of border and title bar<\/h1>\n<p>Use <strong>FormBorderStyle<\/strong> to determine whether the\u00a0end-user can resize the form.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/hw8kes41(v=vs.110).aspx\">FormBorderStyle<\/a><br \/>\n<b>Default value<\/b>: Sizeable<\/p>\n<p>Values (Default: <em>Sizable<\/em>):<\/p>\n<blockquote><p><em>None<\/em><br \/>\nNo border or title bar. The end-user cannot\u00a0drag or resize the form.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"NoBorder\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/NoBorder.png\" alt=\"NoBorder\" width=\"199\" height=\"86\" border=\"0\" \/><\/p>\n<p><em>FixedSingle<br \/>\n<\/em>A fixed, single-line border. The end-user cannot resize this form.<\/p>\n<p><em>Fixed3D<\/em><br \/>\nA fixed, three-dimensional border. The end-user cannot resize this form.<\/p>\n<p><em>FixedDialog<\/em><br \/>\nA thick, fixed dialog-style border. The end-user cannot resize this form.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"FixedDialog\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/FixedDialog.png\" alt=\"FixedDialog\" width=\"215\" height=\"124\" border=\"0\" \/><\/p>\n<p><em>Sizable (Default)<\/em><br \/>\nThe end-user can resize this form.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"Sizeable\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/Sizeable.png\" alt=\"Sizeable\" width=\"215\" height=\"137\" border=\"0\" \/><\/p>\n<p><em>FixedToolWindow<\/em><br \/>\nThe end-user cannot resize this form.<\/p>\n<p>By design,\u00a0a tool window does not appear in the taskbar or in the window thumbnail collection that appears when the user presses ALT+TAB. However, this does not appear to be true on Windows 10. When you use the FixedToolWindow value,\u00a0you are supposed to set the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.form.showintaskbar.aspx\">ShowInTaskbar<\/a> property to False;\u00a0its default value is True.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"FixedToolWindow\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/FixedToolWindow.png\" alt=\"FixedToolWindow\" width=\"215\" height=\"120\" border=\"0\" \/><\/p>\n<p><em>SizableToolWindow<\/em><\/p>\n<p>The end-user can resize this form.<\/p>\n<p>By design,\u00a0a tool window does not appear in the taskbar or in the window thumbnail collection that appears when the user presses ALT+TAB. However, this does not appear to be true on Windows 10. When you use the FixedToolWindow value,\u00a0you are supposed to set the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.form.showintaskbar.aspx\">ShowInTaskbar<\/a> property to False;\u00a0its default value is True.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"SizeableToolWindow\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/SizeableToolWindow.png\" alt=\"SizeableToolWindow\" width=\"217\" height=\"133\" border=\"0\" \/><\/p><\/blockquote>\n<p>NOTE: Some borders, such as <em>Fixed3D<\/em> and <em>FixedSingle,<\/em>\u00a0might be affected by the operating system and Windows theme.<\/p>\n<p><a name=\"Icon\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>Icon property: Gets and sets the form icon<\/h1>\n<p>The form\u00a0icon is displayed in the system menu box and appears when the form is minimized. Use the Icon property to display a custom icon. The value of the\u00a0<strong>FormBorderStyle\u00a0<\/strong>and <strong>ShowIcon<\/strong> properties might hide the form icon.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.drawing.icon(v=vs.110).aspx\" target=\"_blank\">System.Drawing.Icon<\/a><br \/>\n<b>Default value<\/b>: (Default icon). The default icon might be affected by the operating system and Windows theme.<\/p>\n<p>To change the icon, in the Properties pane, in the <strong>Icon<\/strong> property\u00a0value, click the ellipsis, then navigate to the icon file. You can set the Icon property value\u00a0to\u00a0any .ico file.<\/p>\n<p style=\"padding-left: 30px;\">\u00a0<a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-16.00.25.png\" rel=\"attachment wp-att-11178\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-11178\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-16.00.25.png\" alt=\"Screenshot 2016-02-11 16.00.25\" width=\"379\" height=\"157\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-16.00.25.png 444w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-11-16.00.25-300x124.png 300w\" sizes=\"auto, (max-width: 379px) 100vw, 379px\" \/><\/a><\/p>\n<p>To reset the icon to its default value, in the Properties pane, click the current value, and then click <strong>Delete<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<p>Default Icon:<\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"DefaultIcon\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/DefaultIcon.png\" alt=\"DefaultIcon\" width=\"143\" height=\"105\" border=\"0\" \/><\/p>\n<p>Custom Icon:<\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"CustomIcon\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/CustomIcon1.png\" alt=\"CustomIcon\" width=\"143\" height=\"105\" border=\"0\" \/><\/p>\n<p><a name=\"StartPosition\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>StartPosition property: Determines where the form appears<\/h1>\n<p>Use the <strong>StartPosition<\/strong> property to determine where on the screen the form first appears. For example, you can place the form\u00a0in\u00a0center of the screen or the parent window.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.formstartposition(v=vs.110).aspx\" target=\"_blank\">System.Windows.Forms.FormStartPosition<\/a><br \/>\n<b>Default value<\/b>: WindowsDefaultLocation<\/p>\n<p>Values (Default: <em>WindowsDefaultLocation<\/em>):<\/p>\n<blockquote><p><em>Manual<\/em><br \/>\nThe position of the form is determined by the value of the <strong><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.control.location.aspx\">Location<\/a><\/strong> property.<\/p>\n<p><em>CenterScreen<\/em><br \/>\nThe form is centered on the display and has the dimensions specified\u00a0by the value of the\u00a0<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.form.size(v=vs.90).aspx\" target=\"_blank\"><strong>Size<\/strong> <\/a>property of the form.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/Center-Location.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"Center Location\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/Center-Location_thumb.png\" alt=\"Center Location\" width=\"244\" height=\"148\" border=\"0\" \/><\/a><\/p>\n<p><em>WindowsDefaultLocation<\/em> (Default)<br \/>\nThe form is positioned at the default location for the current version of Windows. Its size is determined by the by the value of the\u00a0<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.form.size(v=vs.90).aspx\" target=\"_blank\"><strong>Size<\/strong> <\/a>property of the form.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/Default-Location.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"Default Location\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/Default-Location_thumb.png\" alt=\"Default Location\" width=\"244\" height=\"148\" border=\"0\" \/><\/a><\/p>\n<p><em>WindowsDefaultBounds<\/em><br \/>\nThe form is positioned at the Windows default location and has the bounds determined by Windows default.<\/p>\n<p><em>CenterParent<\/em><br \/>\nThe form is centered within the bounds of its parent form.<\/p><\/blockquote>\n<p><a name=\"WindowState\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>WindowState property: Opens the form minimized or maximized<\/h1>\n<p>Use\u00a0the WindowState property to maximize or minimize when it is first displayed.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.formwindowstate(v=vs.110).aspx\" target=\"_blank\">System.Windows.Forms.FormWindowState<\/a><br \/>\n<b>Default value<\/b>: WindowsDefaultLocation<\/p>\n<p>&nbsp;<\/p>\n<p>Values (Default: <em>Normal<\/em>):<\/p>\n<blockquote><p><em>Normal<\/em> (Default)<br \/>\nOpens at standard size.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/NormalState.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"NormalState\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/NormalState_thumb.png\" alt=\"NormalState\" width=\"244\" height=\"154\" border=\"0\" \/><\/a><\/p>\n<p><em>Maximized<\/em><br \/>\nOpens maximized.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/Maximized.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"Maximized\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/Maximized_thumb.png\" alt=\"Maximized\" width=\"244\" height=\"155\" border=\"0\" \/><\/a><\/p>\n<p><em>Minimized<\/em><br \/>\nOpens minimized.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/MinimizedState.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"MinimizedState\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/MinimizedState_thumb.png\" alt=\"MinimizedState\" width=\"244\" height=\"154\" border=\"0\" \/><\/a><\/p><\/blockquote>\n<p><a name=\"ControlBox\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>ControlBox property: Show\/hide system menu<\/h1>\n<p>Use the <strong>ControlBox<\/strong> property to show and hide\u00a0the system menu that contains the Minimize, Maximize, and Close buttons. A value of False also hides the Windows icon on the top left corner of the window, if the operating system adds one.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.boolean(v=vs.110).aspx\" target=\"_blank\">System.Boolean<\/a><br \/>\n<b>Default value<\/b>: True<\/p>\n<p>NOTES:<\/p>\n<ul>\n<li>The Form object also has <a href=\"#MinimizeBox\">MinimizeBox<\/a> and <a href=\"#MaximizeBox\" target=\"_blank\">MaximizeBox<\/a>\u00a0properties to show\/hide each element on the system menu. If <strong>ControlBox<\/strong> is False, the system menu, including the CancelBox (X)\u00a0does not appear, regardless of the value of the other properties.<\/li>\n<li>If you set the <strong>ControlBox<\/strong> property to <em>False<\/em>, be sure to add a way to close the form.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Values (Default: <em>True<\/em>):<\/p>\n<p><em>True<\/em> (Default):<\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"FormWithContolBox\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/FormWithContolBox1.png\" alt=\"FormWithContolBox\" width=\"215\" height=\"124\" border=\"0\" \/><\/p>\n<p><em>False:<\/em><\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"FormWithoutControlBox\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/FormWithoutControlBox1.png\" alt=\"FormWithoutControlBox\" width=\"215\" height=\"124\" border=\"0\" \/><\/p>\n<p><a name=\"MaximizeBox\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>MaximizeBox property: Show\/hide maximize button<\/h1>\n<p>Determines whether\u00a0the form has a maximize button in the upper right corner of its\u00a0title bar.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.boolean(v=vs.110).aspx\" target=\"_blank\">System.Boolean<\/a><br \/>\n<b>Default value<\/b>: True<\/p>\n<p>When the value of ControlBox is False, the maximize button does not appear, regardless of the value of the MaximizeBox property.<\/p>\n<p>MaximizeBox set to <em>False<\/em>:<\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"MaximizeButtonFalse\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/MaximizeButtonFalse.png\" alt=\"MaximizeButtonFalse\" width=\"215\" height=\"124\" border=\"0\" \/><\/p>\n<p><a name=\"MinimizeBox\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>MinimizeBox property: Show\/hide minimize button<\/h1>\n<p>Determines whether a form has a minimize button in the upper right corner of its\u00a0title bar.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.boolean(v=vs.110).aspx\" target=\"_blank\">System.Boolean<\/a><br \/>\n<b>Default value<\/b>: True<\/p>\n<p>When the value of <strong>ControlBox<\/strong> is False, the maximize button does not appear, regardless of the value of the <strong>MaximizeBox<\/strong> property.<\/p>\n<p>MinimizeBox set to <em>False<\/em>:<\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"MinimizeButtonFalse\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/MinimizeButtonFalse.png\" alt=\"MinimizeButtonFalse\" width=\"215\" height=\"124\" border=\"0\" \/><\/p>\n<p>MaximizeBox and MinimizeBox set to <em>False<\/em>:<\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"MinandMaxButtonsFalse\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/MinandMaxButtonsFalse.png\" alt=\"MinandMaxButtonsFalse\" width=\"215\" height=\"124\" border=\"0\" \/><\/p>\n<p><a name=\"AcceptButton\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>AcceptButton property: Button that is clicked on Enter<\/h1>\n<p>The <strong>AcceptButton<\/strong> property of the form determines which button&#8217;s Click event is raised\u00a0when the user presses the ENTER key. Typically, the value of <strong>AcceptButton<\/strong> is the variable that contains the OK button object ($buttonOK), but you can use this property to change it to any button on the form, such as a Start button that performs the primary action of the form.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.ibuttoncontrol(v=vs.110).aspx\" target=\"_blank\">System.Windows.Forms.iButtonControl<\/a><br \/>\n<b>Default value<\/b>: (None)<\/p>\n<p>When the end-user presses enter, the <strong>Click<\/strong> event of the <strong>AcceptButton<\/strong> is raised, and the event handler for the buttons Click event runs. You can also change and query the value of the <strong>AcceptButton<\/strong> in your script.<\/p>\n<p><a name=\"CancelButton\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>CancelButton property: The button that is clicked on ESC<\/h1>\n<p>The <strong>CancelButton<\/strong> property of the form determines which button&#8217;s Click event is raised\u00a0when the user presses the ESC key. Typically, the value of <strong>CancelButton<\/strong> is the variable that contains the OK button object ($buttonOK), but you can use this property to change it to any button on the form, such as a Start button that performs the primary action of the form.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.ibuttoncontrol(v=vs.110).aspx\" target=\"_blank\">System.Windows.Forms.iButtonControl<\/a><br \/>\n<b>Default value<\/b>: (None)<\/p>\n<p><a name=\"BackgroundImage\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>BackgroundImage property: Sets a background image for the form<\/h1>\n<p>Use the BackgroundImage property to customize the form with a texture or graphic.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.drawing.image(v=vs.110).aspx\" target=\"_blank\">System.Drawing.Image<\/a><br \/>\n<b>Default value<\/b>: (None)<\/p>\n<p>To set a background image, in the Properties pane, on the BackgroundImage row, click the ellipsis, and then navigate to an image file.<\/p>\n<p style=\"padding-left: 30px;\">\u00a0<a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-12-14.09.59.png\" rel=\"attachment wp-att-11199\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11199\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-12-14.09.59.png\" alt=\"Screenshot 2016-02-12 14.09.59\" width=\"429\" height=\"252\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-12-14.09.59.png 429w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2016-02-12-14.09.59-300x176.png 300w\" sizes=\"auto, (max-width: 429px) 100vw, 429px\" \/><\/a><\/p>\n<p><a name=\"BackgroundImageLayout\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>BackgroundImageLayout property: Layout of the background\u00a0image<\/h1>\n<p>Use this property to change the default presentation of the background image.<\/p>\n<p><strong>Value type<\/strong>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.imagelayout(v=vs.110).aspx\">System.Windows.Forms.ImageLayout<br \/>\n<\/a><b>Default value<\/b>: Tile<\/p>\n<p>Values (Default: Tile)<\/p>\n<blockquote><p><em><strong>None<\/strong><\/em><br \/>\nThe image is left-aligned at the top\u00a0of the form.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"BackgroundLayoutNone\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/BackgroundLayoutNone.png\" alt=\"BackgroundLayoutNone\" width=\"225\" height=\"244\" border=\"0\" \/><\/p>\n<p><em><strong>Tile<\/strong><\/em><br \/>\nMultiple instances of the image are arranged in the form rectangle.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"BackgroundLayoutTitle\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/BackgroundLayoutTitle.png\" alt=\"BackgroundLayoutTitle\" width=\"225\" height=\"244\" border=\"0\" \/><\/p>\n<p><em><strong>Center<\/strong><\/em><br \/>\nThe image is centered in the form.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"BackgroundLayoutCenter\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/BackgroundLayoutCenter.png\" alt=\"BackgroundLayoutCenter\" width=\"225\" height=\"244\" border=\"0\" \/><\/p>\n<p><em><strong>Stretch<\/strong><\/em><br \/>\nThe image is enlarged to occupy the entire form.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"BackgroundLayoutStretch\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/BackgroundLayoutStretch.png\" alt=\"BackgroundLayoutStretch\" width=\"225\" height=\"244\" border=\"0\" \/><\/p>\n<p><strong><em>Zoom<\/em><\/strong><br \/>\nThe image is enlarged within the form.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"BackgroundLayoutZoom\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/05\/BackgroundLayoutZoom.png\" alt=\"BackgroundLayoutZoom\" width=\"244\" height=\"186\" border=\"0\" \/><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p><a name=\"Load\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>Load event: Occurs before a form is displayed.<\/h1>\n<p>Use the Load event to initialize property values just before the form is displayed.<\/p>\n<p>The values in the Properties pane of PowerShell Studio and PrimalScript are set when the objects are created (New-Object), which is shortly before the Load event is raised. You can use the Load event to get the initial values or set new values.<\/p>\n<p>When you create a new form, PowerShell Studio and PrimalScript automatically an event handler for the Form_Load event.<\/p>\n<pre><span style=\"color: #8b0000;\">$FormEvent_Load<\/span><span style=\"color: #0000ff;\">=<\/span><span style=\"color: #000000;\">{\r\n    <\/span><span style=\"color: #008000;\">#TODO: Initialize Form Controls here<\/span><span style=\"color: #000000;\">\r\n}<\/span><\/pre>\n<p><a name=\"FormClosing\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>FormClosing event: Occurs before the form is closed.<\/h1>\n<p>Use the FormClosing event to clean up and finalize before the form closes. You can also cancel the closing by setting the <strong>Cancel<\/strong> property to true:<\/p>\n<pre><span style=\"color: #8b0000;\">$form1_FormClosing<\/span><span style=\"color: #0000ff;\">=<\/span><span style=\"color: #000000;\">[System.Windows.Forms.FormClosingEventHandler]{\r\n<\/span><span style=\"color: #008000;\">#Event Argument: $_ = [System.Windows.Forms.FormClosingEventArgs]<\/span>\r\n    <span style=\"color: #8b0000;\">$_<\/span><span style=\"color: #000000;\">.Cancel <\/span><span style=\"color: #0000ff;\">=<\/span> <span style=\"color: #8b0000;\">$true<\/span><span style=\"color: #000000;\">\r\n}<\/span><\/pre>\n<pre><span style=\"color: #000000;\">\u00a0<\/span><\/pre>\n<p><strong><span style=\"font-size: small;\">Important Methods:<\/span><\/strong><\/p>\n<p><a name=\"Close\"><\/a><br \/>\n<b>&nbsp;<\/b><\/p>\n<h1>Close method: Closes the form window<\/h1>\n<p>Typically, you use the Close method in the event handler for a Close button.<\/p>\n<pre><span style=\"color: #8b0000;\">$buttonOK_Click<\/span><span style=\"color: #0000ff;\">=<\/span><span style=\"color: #000000;\">{\r\n    <\/span><span style=\"color: #8b0000;\">$form1<\/span><span style=\"color: #000000;\">.Close()\r\n}\r\n<\/span><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Spotlight on Controls series describes the controls, that is, the objects in the System.Windows.Forms namespace, so you can use them effectively when building GUI apps in PowerShell Studio and PrimalScript. Each post focuses on one control and lists its most important properties, methods, and events, including the default event that PowerShell Studio adds to [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[283,575,644,25],"tags":[641,28,633,327],"class_list":["post-2960","post","type-post","status-publish","format-standard","hentry","category-howto","category-primalforms-2011-software-news","category-spotlight-on-controls","category-windows-powershell","tag-controls","tag-powershell","tag-primalforms-2011","tag-winform"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/2960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=2960"}],"version-history":[{"count":49,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/2960\/revisions"}],"predecessor-version":[{"id":11209,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/2960\/revisions\/11209"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=2960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=2960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=2960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}