{"id":3077,"date":"2011-06-13T21:50:33","date_gmt":"2011-06-14T05:50:33","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=3077"},"modified":"2016-01-22T20:32:51","modified_gmt":"2016-01-23T04:32:51","slug":"primalforms-2011-spotlight-on-the-textbox-control","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2011\/06\/13\/primalforms-2011-spotlight-on-the-textbox-control\/","title":{"rendered":"Spotlight on the TextBox 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 Textbox control.<\/p>\n<h1>TextBox [System.Windows.Forms.TextBox]<\/h1>\n<p>Creates\u00a0a\u00a0text box for displaying text and collecting user input in text format.<\/p>\n<ul>\n<li>MSDN Page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.textbox(v=vs.110).aspx\" target=\"_blank\">System.Windows.Forms.TextBox<\/a><\/li>\n<li>Default Event: <a href=\"#TextChanged\">TextChanged<\/a><\/li>\n<\/ul>\n<p>Tip: Because many of the properties of Textbox objects are inherited from the TextBoxBase class, these properties are available on other controls that are derived from TextBoxBase, including MaskedTextBox and RichTextBox.<\/p>\n<p>Need to scroll to the end of a textbox? Try this Textbox tip!<\/p>\n<h1>Important Properties<\/h1>\n<table class=\"nicetable\">\n<tbody>\n<tr>\n<td><a href=\"#Text\">Text<\/a><\/td>\n<td>Get, set, change the text in a textbox<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#Font\">Font<\/a><\/td>\n<td>Determine the style and size of the textbox text<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#Multiline\">Multiline<\/a><\/td>\n<td>Resize and allow multiple lines of text<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#ReadOnly\">ReadOnly<\/a><\/td>\n<td>Determines whether the user can change Textbox text<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#MaxLength\">MaxLength<\/a><\/td>\n<td>Maximum characters a user can enter<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#WordWrap\">WordWrap<\/a><\/td>\n<td>Enables\/disables word wrap<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#ScrollBars\">ScrollBars<\/a><\/td>\n<td>Determines which scroll bars are enabled<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#UseSystemPasswordChar\">UseSystemPasswordChar<\/a><\/td>\n<td>Displays a character instead of typed text<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#AutoCompleteMode\">AutoCompleteMode<\/a><\/td>\n<td>Determines the text completion behavior<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#AutoCompleteSource\">AutoCompleteSource<\/a><\/td>\n<td>Specifies the data source for the auto-complete strings<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#AutoCompleteCustomSource\">AutoCompleteCustomSource<\/a><\/td>\n<td>Specifies auto-complete values<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>Important Methods<\/h1>\n<table class=\"nicetable\">\n<tbody>\n<tr>\n<td><a href=\"#AppendText\">AppendText<\/a><\/td>\n<td>Appends text to the text in the text box<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>Important Events<\/h1>\n<table class=\"nicetable\">\n<tbody>\n<tr>\n<td><a href=\"#TextChanged\">TextChanged<\/a><\/td>\n<td>event: Occurs when the value of the Text property changes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<p><a name=\"Text\"><\/a><\/p>\n<h1>Text property: Manages the text in the textbox<\/h1>\n<p>Use the Text property to get, set, and change the text in the textbox.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/a19tt6sk(v=vs.110).aspx\" target=\"_blank\">Text<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.string(v=vs.110).aspx\" target=\"_blank\">System.String<\/a><\/li>\n<li>Default value: (None)<\/li>\n<\/ul>\n<p>Get the text in a textbox. This can be text that a user typed in the textbox or text that your script added to the textbox.<\/p>\n<pre lang=\"PowerShell\">$text = $textbox1.Text<\/pre>\n<p>Set the text in a textbox. This command makes text appear in the textbox.<\/p>\n<pre lang=\"PowerShell\">$textbox1.Text = \"Display this text\"<\/pre>\n<p>Display cmdlet output in a textbox. Be sure to format the content into string output.<\/p>\n<pre lang=\"PowerShell\">$textboxProcess.Text = Get-Process | Format-Table  | Out-String<\/pre>\n<p><a name=\"Font\"><\/a><\/p>\n<h1>Font property: Determines the style and size of the text in the textbox<\/h1>\n<p>Use the Font property to get, set, or change the font of text in the Textbox.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.Control.Font.aspx\" target=\"_blank\">Font<\/a><\/li>\n<li>Value Type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.drawing.font(v=vs.110).aspx\" target=\"_blank\">System.Drawing.Font<\/a><\/li>\n<li>Default: Microsoft Sans Serif 8.25<\/li>\n<\/ul>\n<p>To display\u00a0Windows PowerShell\u00a0output correctly aligned, use a\u00a0monospace font, such as Courier New, Consolas, or Lucida Console.<\/p>\n<p>Output in Microsoft Sans Serif:<\/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=\"VariableSizedFont\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/VariableSizedFont.png\" alt=\"VariableSizedFont\" width=\"223\" height=\"191\" border=\"0\" \/><\/p>\n<p>Same output in Lucida Console:<\/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=\"FixSizeFont\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/FixSizeFont.png\" alt=\"FixSizeFont\" width=\"265\" height=\"169\" border=\"0\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Tip:\u00a0 To set the font to display Windows PowerShell output, right-click the textbox, click <strong>Apply Property Set<\/strong>, and then click <strong>Apply Console Font<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2015-12-22-09.51.56.png\" rel=\"attachment wp-att-10914\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-10914\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2015-12-22-09.51.56-300x160.png\" alt=\"Screenshot 2015-12-22 09.51.56\" width=\"300\" height=\"160\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2015-12-22-09.51.56-300x160.png 300w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2015-12-22-09.51.56-768x410.png 768w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2015-12-22-09.51.56.png 1005w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/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=\"Multiline\"><\/a><\/p>\n<h1><strong>Multiline property: Resize and\u00a0permit multiple lines of text<\/strong><\/h1>\n<p>Use the Multiline property to resize a textbox or allow you or the user to type multiple lines of text in the textbox. By default, the textbox is single line.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.TextBox.Multiline.aspx\" target=\"_blank\">Multiline<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.boolean(v=vs.110).aspx\" target=\"_blank\">System.Boolean<\/a> (True, False)<\/li>\n<li>Default value: False<\/li>\n<\/ul>\n<p>For example, the following images show a single-line (Multiline=$False) and multi-line (Multiline = $True) textbox.<\/p>\n<p>Single Line TextBox:<\/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=\"Single Line TextBox\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Single-Line-TextBox.png\" alt=\"Single Line TextBox\" width=\"211\" height=\"33\" border=\"0\" \/><\/p>\n<p>Multi-Line TextBox:<\/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=\"MultilineTextBox\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/MultilineTextBox.png\" alt=\"MultilineTextBox\" width=\"215\" height=\"71\" border=\"0\" \/><\/p>\n<p><a name=\"ReadOnly\"><\/a><\/p>\n<h1><strong>ReadOnly property: Determines whether the user can change Textbox text<\/strong><\/h1>\n<p>Use the ReadOnly property when you want to display text and prevent the user from changing the contents.<\/p>\n<ul>\n<li>MSDN page: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.TextBoxBase.ReadOnly.aspx\" target=\"_blank\">ReadOnly<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.boolean(v=vs.110).aspx\" target=\"_blank\">System.Boolean<\/a> (True, False)<\/li>\n<li>Default value: False<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Important<\/strong>: When the ReadOnly property is True, the TextBox background\u00a0is grey, the text is black, and changes to the ForeColor (text color) property have no effect. To change the color of the Textbox background and make changes to the ForeColor property effective,\u00a0use a RichTextBox or change\u00a0the BackColor property.<\/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=\"ReadOnly TextBox\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/ReadOnly-TextBox.png\" alt=\"ReadOnly TextBox\" width=\"216\" height=\"41\" border=\"0\" \/><\/p>\n<p><a name=\"MaxLength\"><\/a><\/p>\n<h1><strong>MaxLength property:\u00a0Maximum characters a user can enter<\/strong><\/h1>\n<p>Use MaxLength property\u00a0to specify the maximum number of characters that an end-user can\u00a0enter into the textbox, such as when a user name or password has a length limit. The MaxLength property value does not\u00a0limit that the text that you (as the designer) or your script can enter in the textbox.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.TextBoxBase.MaxLength.aspx\" target=\"_blank\">MaxLength<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.int32.aspx\" target=\"_blank\">System.Int32<\/a><\/li>\n<li>Default value: 32767<\/li>\n<\/ul>\n<p><a name=\"WordWrap\"><\/a><\/p>\n<h1><strong>WordWrap property:\u00a0Enables\/disables word wrap<\/strong><\/h1>\n<p>When WordWrap is $True, lines of text that\u00a0exceed the length of a multiline textbox are\u00a0restarted on\u00a0the next\u00a0line. Set the value of WordWrap to $False when you do not want to alter the formatting of the text, such as text in Windows PowerShell output.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.TextBoxBase.WordWrap.aspx\" target=\"_blank\">WordWrap<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.boolean(v=vs.110).aspx\" target=\"_blank\">System.Boolean<\/a> (True, False)<\/li>\n<li>Default value: True<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>WordWrap has no effect on single-line textboxes, but it is equally effective on text that the end-user types and text that the scripts\u00a0assigns to the textbox.\u00a0When word-wrapping isn&#8217;t useful, consider resizing the textbox to fit the text.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2015-12-22-21.59.54.png\" rel=\"attachment wp-att-10922\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-10922\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2015-12-22-21.59.54-300x232.png\" alt=\"Screenshot 2015-12-22 21.59.54\" width=\"300\" height=\"232\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2015-12-22-21.59.54-300x232.png 300w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Screenshot-2015-12-22-21.59.54.png 477w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a name=\"ScrollBars\"><\/a><\/p>\n<h1><strong>ScrollBars property: Determines which scroll bars are enabled<\/strong><\/h1>\n<p>Use the ScrollBars property to enable and disable horizontal and vertical scroll bars on multiline textboxes.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.TextBox.ScrollBars.aspx\" target=\"_blank\">ScrollBars<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.scrollbars.aspx\" target=\"_blank\">System.Windows.Forms.Scrollbars<\/a> enumeration<\/li>\n<li>Default value: None<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Valid values:<\/p>\n<blockquote><p><em>None<\/em><br \/>\nNo scroll bars are shown.<\/p>\n<p><em>Horizontal<\/em><br \/>\nOnly horizontal scroll bars are shown.<\/p>\n<p><em>Vertical<\/em><br \/>\nOnly vertical scroll bars are shown.<\/p>\n<p><em>Both<\/em><br \/>\nBoth horizontal and vertical scroll bars are shown.<\/p><\/blockquote>\n<p>NOTE: Scroll bars are active only when the text exceeds the horizontal or vertical dimension of the textbox.<\/p>\n<p><a name=\"UseSystemPasswordChar\"><\/a><\/p>\n<h1><strong>UseSystemPasswordChar property: Displays a\u00a0character instead of typed text<\/strong><\/h1>\n<p>Use the <strong>UseSystemPasswordChar\u00a0<\/strong>property to mask characters that are typed into the textbox. Instead of the typed character, a character selected by the operating system, typically *, appears. To set the character, use the <strong>PasswordChar<\/strong> property. When both are set, <strong>UseSystemPasswordChar<\/strong> takes precedence.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.TextBox.UseSystemPasswordChar.aspx\" target=\"_blank\">UseSystemPasswordChar<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.boolean(v=vs.110).aspx\" target=\"_blank\">System.Boolean<\/a> (True, False)<\/li>\n<li>Default value: False<\/li>\n<\/ul>\n<p>&nbsp;<\/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=\"Password TextBox\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/06\/Password-TextBox.png\" alt=\"Password TextBox\" width=\"146\" height=\"42\" border=\"0\" \/><\/p>\n<h1><strong><em>Auto Complete Properties:<\/em><\/strong><\/h1>\n<p>Use the following properties to\u00a0manage\u00a0the built-in\u00a0auto-complete features of a TextBox.<\/p>\n<p><a name=\"AutoCompleteMode\"><\/a><\/p>\n<h1><strong>AutoCompleteMode property:\u00a0Determines the text completion behavior<br \/>\n<\/strong><\/h1>\n<p>Use the <strong>AutoCompleteMode<\/strong> property to select how the auto-completion occurs.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.TextBox.AutoCompleteMode.aspx\" target=\"_blank\">AutoCompleteMode<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.autocompletemode.aspx\">System.Windows.Forms.AutoCompleteMode<\/a><\/li>\n<li>Default value: None<\/li>\n<\/ul>\n<p>Valid values :<\/p>\n<blockquote>\n<dl>\n<dt><em>Append<\/em><\/dt>\n<dd>Appends the remainder of the most likely candidate string to the existing characters, highlighting the appended characters.<\/p>\n<\/dd>\n<dt><em>Suggest<\/em><\/dt>\n<dd>Displays the auxiliary drop-down list associated with the edit control. This drop-down is populated with one or more suggested completion strings.\n<\/dd>\n<dt><em>SuggestAppend<\/em><\/dt>\n<dd>Appends both Suggest and Append options.\n<\/dd>\n<dt><em>None<\/em>\u00a0(Default)<\/dt>\n<dd>Disables automatic completion.<\/dd>\n<\/dl>\n<\/blockquote>\n<p><a name=\"AutoCompleteSource\"><\/a><\/p>\n<h1><strong>AutoCompleteSource property: Specifies the data source for auto-completing<\/strong><\/h1>\n<p>Use the AutoCompleteSource property to specify the source of the data used to complete\u00a0text in a textbox. You can use a custom list of words or select a built in source, such as the file system.<\/p>\n<ul>\n<li>MSDN page: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.TextBox.AutoCompleteSource.aspx\" target=\"_blank\">AutoCompleteSource<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.autocompletesource.aspx\">System.Windows.Forms.AutoCompleteSource<\/a>\u00a0enumeration<\/li>\n<li>Default value: None<\/li>\n<\/ul>\n<p>Valid values:<\/p>\n<blockquote><p><em>FileSystem<\/em><br \/>\nUses the file system as the source. The field auto-completes file and folder names.<\/p>\n<p><em>HistoryList<\/em><br \/>\nAuto-completes\u00a0Uniform Resource Locators (URLs) in the history list.<\/p>\n<p><em>RecentlyUsedList<\/em><br \/>\nAuto-completes\u00a0recently used\u00a0Uniform Resource Locators (URLs).<\/p>\n<p><em>AllUrl<\/em><br \/>\nCombines HistoryList and RecentlyUsedList contents.<\/p>\n<p><em>AllSystemSources<br \/>\n<\/em>Combines FileSystem and AllUrl sources. This is the default value when <strong>AutoCompleteMode\u00a0<\/strong>is set to a value other than Default.<\/p>\n<p><em>FileSystemDirectories<\/em><br \/>\nAuto-completes only\u00a0file system\u00a0directory names,\u00a0not file names.<\/p>\n<p><em>CustomSource<\/em><br \/>\nAuto-completes the strings specified by the AutoCompleteCustomSource property.<\/p>\n<p><em>None <\/em>(Default)<br \/>\nDoes not specify an auto-complete source.\u00a0This is the default value of AutoCompleteSource.<\/p>\n<p><em>ListItems<\/em><br \/>\nApplies only to the ComboBox control. Specifies that the items of the ComboBox represent the source.<\/p><\/blockquote>\n<p><a name=\"AutoCompleteCustomSource\"><\/a><\/p>\n<h1><strong>AutoCompleteCustomSource property: Specifies auto-complete values<\/strong><\/h1>\n<p>Use the AutoCompleteCustomSource property to define your own list of auto-complete strings. This list is used when the value of the\u00a0<strong>AutoCompleteSource<\/strong> property\u00a0value is\u00a0<strong>CustomSource<\/strong>.<\/p>\n<ul>\n<li>MSDN page: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms.TextBox.AutoCompleteCustomSource.aspx\" target=\"_blank\">AutoCompleteCustomSource<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.autocompletestringcollection.aspx\" target=\"_blank\">System.Windows.Forms.AutoCompleteStringCollection<\/a><\/li>\n<li>Default value: None<\/li>\n<\/ul>\n<p>In this\u00a0example, the auto-complete source is a list of computer names in the Computers.txt file. The <strong>AddRange<\/strong> method adds a collection of items.<\/p>\n<pre lang=\"PowerShell\">$computers = Get-Content C:\\computers.txt\"\r\n$textbox1.AutoCompleteCustomSource.AddRange($computers)<\/pre>\n<p><a name=\"AppendText\"><\/a><\/p>\n<h1>AppendText method: Appends text to the text in the text box<\/h1>\n<p>Use the AppendText method to add\u00a0strings to the value of the Text property of\u00a0a text box. It is more efficient\u00a0than using the += operator.<\/p>\n<p>Note: The AppendText method is defined in the TextBoxBase class and is inherited by its child classes, Textbox, MaskedTextBox, and RichTextBox, and their child classes, such as DataGridTextBox.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.textboxbase.appendtext(v=vs.110).aspx\" target=\"_blank\">AppendText<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.string(v=vs.110).aspx\" target=\"_blank\">System.String<\/a><\/li>\n<li>Default value: None<\/li>\n<\/ul>\n<p>In this example, we use the AppendText method of the Textbox to add a year to a list of years in the textbox.<\/p>\n<pre lang=\"PowerShell\">$textboxOutput.Text = \"2012, 2014, 2015\"\r\nif (Test-Path \"$env:ProgramFiles\\*\\PowerShell Studio 2016\")\r\n{\r\n    $textboxOutput.AppendText(\", 2016`r`n\")\r\n}\r\n<\/pre>\n<p><a name=\"TextChanged\"><\/a><br \/>\n&nbsp;<\/p>\n<h1><strong>TextChanged event: <\/strong>Occurs when the value of the Text property changes<\/h1>\n<p>Use the TextChanged event to respond to a user entering, deleting, or changing the\u00a0Text in a Textbox.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.web.ui.webcontrols.textbox.textchanged(v=vs.110).aspx\" target=\"_blank\">TextChanged<\/a><\/li>\n<li>Default value: None<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>For example, this event handler enables the $buttonSubmit button\u00a0when the text in the $textboxUser textbox is not an empty string.<\/p>\n<pre lang=\"PowerShell\">$textboxUser_TextChanged = {\r\n    $buttonSubmit.Enabled = $textboxUser.Text -ne ''\r\n}<\/pre>\n<p><a name=\"Tip\"><\/a><\/p>\n<h1>How to scroll to the end of a TextBox:<\/h1>\n<p>This tip explains how to position the cursor at the end of the $textbox1 textbox, that is, to the right of text typed in the box.<\/p>\n<pre lang=\"PowerShell\">$textbox1.SelectionStart = $textbox1.Text.Length\r\n$textbox1.ScrollToCaret()<\/pre>\n<p>The first command\u00a0uses the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.textboxbase.selectionstart(v=vs.110).aspx\" target=\"_blank\">SelectionStart property<\/a> of the Textbox to set the starting point of the text at the position of the last character of text in the $textbox1 Textbox. The second command uses the\u00a0<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.textboxbase.scrolltocaret(v=vs.110).aspx\" target=\"_blank\">ScrollToCarat method<\/a> to place the cursor at the SelectionStart value location.<\/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":[575,644,25],"tags":[641,28,633,654,327],"class_list":["post-3077","post","type-post","status-publish","format-standard","hentry","category-primalforms-2011-software-news","category-spotlight-on-controls","category-windows-powershell","tag-controls","tag-powershell","tag-primalforms-2011","tag-textbox","tag-winform"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3077","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=3077"}],"version-history":[{"count":69,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3077\/revisions"}],"predecessor-version":[{"id":11037,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3077\/revisions\/11037"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=3077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=3077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=3077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}