{"id":10666,"date":"2015-12-16T06:00:00","date_gmt":"2015-12-16T14:00:00","guid":{"rendered":"https:\/\/www.sapien.com\/blog\/?p=10666"},"modified":"2016-03-02T14:04:01","modified_gmt":"2016-03-02T22:04:01","slug":"spotlight-on-the-label-control","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2015\/12\/16\/spotlight-on-the-label-control\/","title":{"rendered":"Spotlight on the Label 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\/\">Spotlight on Controls: Common properties and methods<\/a><\/p>\n<p>This post describes the Label control.<\/p>\n<h1>Label Control [System.Windows.Forms.Label]<\/h1>\n<p>Creates a clickable text box in a GUI application. Use a label to display text strings.<\/p>\n<ul>\n<li>MSDN Page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.label(v=vs.110).aspx\" target=\"_blank\">System.Windows.Forms.Label<\/a><\/li>\n<li>Default Event: Click<\/li>\n<\/ul>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb.png\" alt=\"image\" width=\"293\" height=\"136\" border=\"0\" \/><\/a><\/p>\n<p><strong>Tip<\/strong>: To display multiple lines of text, use a Textbox or RichTextBox control.<\/p>\n<hr \/>\n<h2>Important properties of the Label object<\/h2>\n<ul>\n<li><a href=\"#Text\">Text<\/a><\/li>\n<li><a href=\"#Text\">Font<\/a><\/li>\n<li><a href=\"#ForeColor\">ForeColor<\/a><\/li>\n<li><a href=\"#BackColor\">BackColor<\/a><\/li>\n<li><a href=\"#BorderStyle\">BorderStyle<\/a><\/li>\n<li><a href=\"#Image\">Image<\/a><\/li>\n<li><a href=\"#TextAlign\">TextAlign<\/a><\/li>\n<li><a href=\"#Enabled\">Enabled<\/a><\/li>\n<\/ul>\n<h2>Important Events:<\/h2>\n<ul>\n<li><a href=\"#ClickEvent\">Click<\/a><\/li>\n<\/ul>\n<hr \/>\n<p><a name=\"Text\"><\/a><\/p>\n<h1>Text property: Determines the text in the label<\/h1>\n<p>Use the <b>Text<\/b> property to set, get, or change the text that is displayed on the label.<\/p>\n<p><b>Value type<\/b>:\u00a0<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>: (None)<\/p>\n<p>To set the initial value of Text property, that is, the value that appears when the GUI app starts, use the Properties pane. On the Text row, type the text that appears on the Label.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/LabelText.png\" rel=\"attachment wp-att-10766\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10766\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/LabelText-300x209.png\" alt=\"LabelText\" width=\"350\" height=\"244\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/LabelText-300x209.png 300w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/LabelText.png 375w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/Screenshot-2016-02-16-16.58.11.png\" rel=\"attachment wp-att-11280\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-11280\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/Screenshot-2016-02-16-16.58.11.png\" alt=\"Screenshot 2016-02-16 16.58.11\" width=\"347\" height=\"178\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/Screenshot-2016-02-16-16.58.11.png 386w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/Screenshot-2016-02-16-16.58.11-300x154.png 300w\" sizes=\"auto, (max-width: 347px) 100vw, 347px\" \/><\/a><\/p>\n<p>NOTE: When you change the value of the Text property of a Label in the Properties pane, PowerShell Studio changes the name of the variable that stores the Label object in your script. For example, if you change the Text property value to &#8216;Close&#8217;, PowerShell Studio changes all references of the Label variable to $LabelClose.<\/p>\n<p>To get or change the label text while the GUI app is running, use the Text property in the event handlers in your script.<\/p>\n<p>To get the text in the label:<\/p>\n<pre lang=\"PowerShell\">$LabelMain.Text<\/pre>\n<p>To set the text in the label use an assignment statement. You can include variables and expressions in the assigned string value.<\/p>\n<pre lang=\"PowerShell\">$Name = 'PowerShell'\r\n$LabelMain.Text = \"Hello, $Name\"<\/pre>\n<p>To change the text in the label:<\/p>\n<pre lang=\"PowerShell\">$LabelMain_click = {\r\n\r\n    # Get the text currently in the label and evaluate it.\r\n    If ($LabelMain.Text -eq 'Click')\r\n    {\r\n        $LabelMain.Text = 'Clicked' # Change the text in the label.\r\n    }\r\n    Else\r\n    {\r\n        $LabelMain.Text = 'Click'\r\n    }\r\n}<\/pre>\n<p><b>Tip: <\/b>To direct Windows PowerShell to evaluate an expression before inserting the result in a string, use a subexpression. The syntax is <span style=\"color: red;\">$(<\/span> &lt;expression <span style=\"color: red;\">)<\/span>.<\/p>\n<p>For example:<\/p>\n<p>Without subexpression:<\/p>\n<pre lang=\"PowerShell\">$LabelMain.Text = \"Building automation on (Get-Process 'PowerShell Studio').MainWindowTitle\"<\/pre>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-1.png\" alt=\"image\" width=\"433\" height=\"84\" border=\"0\" \/><\/a><\/p>\n<p>With subexpression:<\/p>\n<pre lang=\"PowerShell\">$LabelMain.Text = \"Building automation on $((Get-Process 'PowerShell Studio').MainWindowTitle)\"<\/pre>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-2.png\" alt=\"image\" width=\"432\" height=\"79\" border=\"0\" \/><\/a><\/p>\n<p><a name=\"Font\"><\/a><\/p>\n<h1>Font property: Determines the style and size of the label text<\/h1>\n<p>Use the <b>Font<\/b> property to get, set, or change the font of the label text.<\/p>\n<p><b>Value Type<\/b>: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.drawing.font(v=vs.110).aspx\" target=\"_blank\">System.Drawing.Font<\/a><br \/>\n<b>Default: <\/b>Microsoft Sans Serif 8.25.<\/p>\n<p>To set the font easily, in the Properties pane for the Label, in the Font row, click the ellipsis (\u2026) and then use the Font selector.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-3.png\" alt=\"image\" width=\"586\" height=\"404\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>To display the properties of the Font object, in the Properties pane, click the Font group arrow.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-4.png\" alt=\"image\" width=\"386\" height=\"451\" border=\"0\" \/><\/a><\/p>\n<p>To script a font change, set the Font property to a string with the Font name, size, and style.<\/p>\n<pre lang=\"PowerShell\">$labelMain.Font = 'Segoe UI, 15.75pt, style=Bold, Italic'<\/pre>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-5.png\" alt=\"image\" width=\"264\" height=\"90\" border=\"0\" \/><\/a><\/p>\n<p>To determine other properties of the font, create a System.Drawing.Font object.<\/p>\n<pre lang=\"PowerShell\">$ClickFont = [System.Drawing.Font]::new('Microsoft Sans Serif', 8.25, [System.Drawing.FontStyle]::Regular)\r\n$ClickedFont = [System.Drawing.Font]::new('Segoe UI', 16, [System.Drawing.FontStyle]::Italic)\r\n\r\n$labelMain_Click={\r\n    if ($labelMain.Text -eq 'Click')\r\n    {\r\n        $labelMain.Text = 'Clicked'\r\n        $labelMain.Font = $ClickedFont\r\n    }\r\n    else\r\n    {\r\n        $labelMain.Text = 'Click'\r\n        $labelMain.Font = $ClickFont\r\n    }\r\n}<\/pre>\n<p><b>Tips:<\/b><\/p>\n<ul>\n<li>To enlarge the label automatically to fit its contents, set the <strong>AutoSize<\/strong> property of the Label to $True.<\/li>\n<li>When scripting a font, be sure to set the Font property of the Label. The Text property of the Label does not have a Font property.<\/li>\n<\/ul>\n<p><a name=\"ForeColor\"><\/a><\/p>\n<h1>ForeColor property: Determines the color of the label text.<\/h1>\n<p>Use the ForeColor property to get, set, and change the color of the text in the label.<\/p>\n<p><b>Values:<\/b> Any [System.Drawing.Color] type<br \/>\n<b>Default:<\/b> ControlText (Black)<\/p>\n<p>To set the ForeColor property in the Properties pane.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png\" alt=\"image\" width=\"387\" height=\"384\" border=\"0\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-7.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-7.png\" alt=\"image\" width=\"272\" height=\"117\" border=\"0\" \/><\/a><\/p>\n<p>To set ForeColor property in a script:<\/p>\n<pre lang=\"PowerShell\">$Label1.ForeColor = [System.Drawing.Color]::Red<\/pre>\n<p>-or-<\/p>\n<pre lang=\"PowerShell\">$Label1.ForeColor = \"Red\"<\/pre>\n<p><a name=\"BackColor\"><\/a><\/p>\n<h1>BackColor property: Determines the color of the background in the label<\/h1>\n<p>Use the BackColor property to get, set, and change the color of the label background.<\/p>\n<p><b>Value Type:<\/b> [System.Drawing.Color]<br \/>\n<b>Default:<\/b> (Determined by the operating system. Typically &#8216;Control&#8217;)<\/p>\n<p>To set the BackColor property in a script:<\/p>\n<pre lang=\"PowerShell\">If ($Label1.BackColor -eq 'Control')\r\n{\r\n    $Label1.BackColor = [System.Drawing.Color]::ControlDark\r\n}<\/pre>\n<p>-or-<\/p>\n<pre>$Label1.BackColor = \"ControlDark\"<\/pre>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-8.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-8.png\" alt=\"image\" width=\"281\" height=\"136\" border=\"0\" \/><\/a><\/p>\n<p><a name=\"TextAlign\"><\/a><\/p>\n<h1><strong>TextAlign<\/strong> property: Determines the position of the text in the label<\/h1>\n<p>Use the <b>TextAlign<\/b> property to get, set, or change the alignment of the text relative to the label border.<\/p>\n<p><b>Value Type:<\/b> [System.Drawing.ContentAlignment] enumeration<br \/>\n<b>Values:<\/b> TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight<br \/>\n<b>Default:<\/b> MiddleCenter<br \/>\nTo set the TextAlign property in the Property pane:<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-9.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-9.png\" alt=\"image\" width=\"421\" height=\"197\" border=\"0\" \/><\/a><br \/>\nTo set the TextAlign property in a script:<\/p>\n<pre lang=\"PowerShell\">$label1.TextAlign = 'TopRight'<\/pre>\n<p><a name=\"BorderStyle\"><\/a><\/p>\n<h1>BorderStyle property: Determines the style and thickness of the label border.<\/h1>\n<p>Use the BorderStyle property to get, set, or change the label border. Label borders are fixed. The end-user cannot resize any label border style.<\/p>\n<p><b>Value Type:<\/b> [System.Windows.Forms.BorderStyle] enumerator.<br \/>\n<b>Values:<\/b> None, FixedSingle, Fixed3D<br \/>\n<b>Default:<\/b> None<\/p>\n<pre lang=\"PowerShell\">$label1.BorderStyle = 'None'<\/pre>\n<p>-or-<\/p>\n<pre lang=\"PowerShell\">$label1.BorderStyle = [System.Windows.Forms.BorderStyle]'None'<\/pre>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-10.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-10.png\" alt=\"image\" width=\"336\" height=\"138\" border=\"0\" \/><\/a><\/p>\n<pre lang=\"PowerShell\">$label1.BorderStyle = 'FixedSingle'<\/pre>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-11.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-11.png\" alt=\"image\" width=\"335\" height=\"137\" border=\"0\" \/><\/a><\/p>\n<pre lang=\"PowerShell\">$label1.BorderStyle = 'Fixed3D'<\/pre>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-12.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-12.png\" alt=\"image\" width=\"335\" height=\"137\" border=\"0\" \/><\/a><\/p>\n<p><a name=\"Image\"><\/a><\/p>\n<h1><b>Image<\/b> property: Determines that image that appears on the label<\/h1>\n<p>Use this property to display an icon, bitmap, or image of any type on the label.<\/p>\n<p><b>Value Type:<\/b> [System.Drawing.Image]<br \/>\n<b>Default:<\/b> (None; Same as Form.BackgroundImage)<\/p>\n<p>To add an image from a file to a label, use Image property in the Property pane. Click the ellipsis and, in File Explorer, select a file. PowerShell Studio converts the file into a bitmap string (64-bit byte array) so it is independent of the local system.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-13.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-13.png\" alt=\"image\" width=\"628\" height=\"342\" border=\"0\" \/><\/a><\/p>\n<p>On the label:<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image-14.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-14.png\" alt=\"image\" width=\"337\" height=\"231\" border=\"0\" \/><\/a><\/p>\n<p>Tip: If you are using a label to display an image without text, consider using a PictureBox object.<\/p>\n<p>Note: To add an image to a label, PowerShell Studio converts the image to a 64-bit string and then uses the FromBase64String static method to pass a byte array as the System.Drawing.Image type. It does not pass a path or use any local system values.<\/p>\n<p><a name=\"Enabled\"><\/a><\/p>\n<h1>Enabled property: Determines whether the label can be clicked<\/h1>\n<p>Use the <b>Enabled <\/b>property to temporarily enable or disable the click feature of the label. For example, use <b>Enabled = $false<\/b> to disable the click feature after the label has been clicked or while a function is running.<\/p>\n<p><b>Value Type:<\/b> [System.Boolean] ($True, $False).<br \/>\n<b>Default:<\/b> $True<\/p>\n<p>To completely disable the click feature of the label, omit the Click event handler or enter an empty script block.<\/p>\n<p><b>To set the Enabled property in the script:<\/b><\/p>\n<pre lang=\"PowerShell\">$Label1.Enabled = $false<\/pre>\n<p>For example:<\/p>\n<pre lang=\"PowerShell\">If ($Label1.Text -eq 'Click')\r\n{\r\n    $Label1.Text -eq 'Clicked'\r\n    $Label1.Enabled = $false\r\n}<\/pre>\n<p><a name=\"ClickEvent\"><\/a><\/p>\n<h1>Click event: Determines how the label responds when a user clicks it.<\/h1>\n<p>The event handler for the Click event is called when the label is clicked. Use the Click property to trigger a script block when a user clicks on the button.<\/p>\n<pre lang=\"PowerShell\">$label1_Click={\r\n    $label1.Enabled = $false\r\n    $label1.Text = \"Disabled\"\r\n}<\/pre>\n<p>Before Click event:<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/Label_Click_Before.png\" rel=\"attachment wp-att-10686\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10686\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/Label_Click_Before.png\" alt=\"Label_Click_Before\" width=\"223\" height=\"135\" \/><\/a><\/p>\n<p>After Click event:<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/Label_Click_After.png\" rel=\"attachment wp-att-10687\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10687\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/12\/Label_Click_After.png\" alt=\"Label_Click_After\" width=\"223\" height=\"134\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Note about events: <\/strong><\/p>\n<p>To discover which control called the event script block, use the <strong>$this<\/strong> automatic variable. The $this variable is particularly useful when you have multiple controls calling the same event script block. The $this variable tells which control triggered the event, so you can respond in a control-specific way.<\/p>\n<p>For example, this Click event script block disables the control that called it:<\/p>\n<pre lang=\"PowerShell\">$Disable_Click={ \r\n    $this.Enabled = $false\r\n}<\/pre>\n<p>Looking for more <a href=\"https:\/\/www.sapien.com\/blog\/topics\/spotlight-on-controls\/\" target=\"_blank\">Spotlight posts<\/a>? In PowerShell Studio, in the Toolbox or in the Properties pane, right-click a control and then click &#8216;View Spotlight Article&#8217;.<\/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":31,"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":[932,946,703,644,25],"tags":[135,41,1022,1050,28,988,1048,1049,997],"class_list":["post-10666","post","type-post","status-publish","format-standard","hentry","category-beginners","category-guiprogramming","category-powershell-studio","category-spotlight-on-controls","category-windows-powershell","tag-beginner","tag-gui","tag-guiprogramming","tag-label","tag-powershell","tag-powershell-gui","tag-spotlight","tag-system-windows-forms","tag-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/10666","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\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=10666"}],"version-history":[{"count":42,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/10666\/revisions"}],"predecessor-version":[{"id":11475,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/10666\/revisions\/11475"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=10666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=10666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=10666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}