{"id":6785,"date":"2014-01-30T10:40:21","date_gmt":"2014-01-30T18:40:21","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=6785"},"modified":"2016-01-22T21:42:53","modified_gmt":"2016-01-23T05:42:53","slug":"spotlight-on-the-tooltip-control","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2014\/01\/30\/spotlight-on-the-tooltip-control\/","title":{"rendered":"Spotlight on the ToolTip 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 ToolTip control.<\/p>\n<h1>ToolTip [System.Windows.Forms.ToolTip]<\/h1>\n<p>Represents a small rectangular pop-up window that typically displays help for the feature. The tooltip appears when the\u00a0mouse hovers over\u00a0the control.<\/p>\n<p>Use a ToolTip to display help information about a control with minimal configuration.<\/p>\n<ul>\n<li>MSDN Page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip(v=vs.110).aspx\" target=\"_blank\">System.Windows.Forms.ToolTip<\/a><\/li>\n<li>Default Event: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.popup(v=vs.110).aspx\" target=\"_blank\">Popup<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1>Important Properties<\/h1>\n<table class=\"nicetable\">\n<tbody>\n<tr>\n<td><a href=\"#Active\">Active<\/a><\/td>\n<td>Turns the ToolTip on and off<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#AutomaticDelay\">AutomaticDelay<\/a><\/td>\n<td>Determines three tooltip delay property values<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#InitialDelay\">InitialDelay<\/a><\/td>\n<td>Sets and changes the time before the ToolTip appears<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#IsBalloon\">IsBalloon<\/a><\/td>\n<td>Changes the Tooltip from rectangular to balloon-shaped<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#ReshowDelay\">ReshowDelay<\/a><\/td>\n<td>Sets the time between the display of each tooltip<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#ToolTipIcon\">ToolTipIcon<\/a><\/td>\n<td>Adds an icon to the ToolTip text<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#ToolTipTitle\">ToolTipTitle<\/a><\/td>\n<td>Adds a title to the Tooltip window<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#ToolTipTitle\">ToolTipTitle<\/a><\/td>\n<td>Adds a title to the Tooltip window<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>NOTES: <\/p>\n<ul>\n<li>The <strong><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.backcolor(v=vs.110).aspx\" target=\"_blank\">BackColor<\/a><\/strong> and <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.forecolor(v=vs.110).aspx\" target=\"_blank\"><strong>ForeColor<\/strong><\/a> properties of the ToolTip\u00a0have no effect unless you are using the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.ownerdraw(v=vs.110).aspx\" target=\"_blank\">OwnerDraw<\/a> property of the ToolTip to\u00a0override the appearance\u00a0set by the operating system.<\/li>\n<li>The ToolTip control does not have a Text property. To set the text of a ToolTip, use the <a href=\"#SetToolTip\">SetToolTip<\/a> method.<\/li>\n<\/ul>\n<h1>Important Methods<\/h1>\n<table class=\"nicetable\">\n<tbody>\n<tr>\n<td><a href=\"#SetToolTip\">SetToolTip<\/a><\/td>\n<td>Associates a tooltip with a control and specifies its text.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>How to Create a ToolTip<\/h1>\n<p>To begin, add a ToolTip to a form. The ToolTip control\u00a0appears at the bottom of the Designer window. You do not\u00a0place the ToolTip on the form.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipInSPS.png\" rel=\"attachment wp-att-10995\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10995\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipInSPS.png\" alt=\"ToolTipInSPS\" width=\"388\" height=\"262\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipInSPS.png 671w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipInSPS-300x203.png 300w\" sizes=\"auto, (max-width: 388px) 100vw, 388px\" \/><\/a><\/p>\n<p>When you add a ToolTip to a form, PowerShell Studio\u00a0adds new dynamic\u00a0property, <strong>ToolTip on &lt;ToolTipName&gt;<\/strong>, to all controls in the Designer, including controls that you add after you add the Tooltip control.<\/p>\n<p>To create\u00a0a ToolTip for a control, in the <strong>ToolTip on &lt;ToolTipName&gt;<\/strong> property of the <em>control<\/em> (not the property of the ToolTip), type the ToolTip text.<\/p>\n<p>For example, to create a ToolTip for the $buttonStart button, in the Properties pane for the $buttonStart button, in the <strong>ToolTip on tooltip1<\/strong> property, add a string value.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipProperty.png\" rel=\"attachment wp-att-10998\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10998\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipProperty.png\" alt=\"ToolTipProperty\" width=\"677\" height=\"239\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipProperty.png 1275w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipProperty-300x106.png 300w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipProperty-768x272.png 768w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/ToolTipProperty-1024x362.png 1024w\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" \/><\/a><\/p>\n<p><em><img loading=\"lazy\" decoding=\"async\" style=\"margin: 10px 0px 0px; display: inline; border: 0px;\" title=\"Tip\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/Tip.png\" alt=\"Tip\" width=\"32\" height=\"32\" align=\"left\" border=\"0\" \/><\/em><\/p>\n<p>TIP: As a best practice, keep the ToolTip text short. However, to add multiple lines of text in a ToolTip, use the newline character,<span style=\"color: #ff0000;\">`n<\/span>.<\/p>\n<p>&nbsp;<\/p>\n<p>You can also set or change the control or text of a ToolTip in your script. This is useful when the text is stored in a variable or you want to change the control or text of a tooltip after the form loads. <\/p>\n<p>To set or change a ToolTip, use the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.settooltip(v=vs.110).aspx\" target=\"_blank\">SetToolTip<\/a> method of the ToolTip. The SetToolTip method takes two arguments, the variable that contains the control and the ToolTip text (or a variable that contains the text). <\/p>\n<p>For example, this statement associates $tooltip1 with $buttonStart and specifies its text.<\/p>\n<pre lang=\"PowerShell\">$tooltip1.SetToolTip($buttonStart, \"To start the task, click Start.\")<\/pre>\n<p>In this example, the statement associates $tooltip1 with $buttonStart and uses the text in a variable. This technique allows you to localize your UI text. For more information, see <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113262\">about_Scripts_Internationalization<\/a>.<\/p>\n<pre lang=\"PowerShell\">$tipStart = \"To start the task, click Start.\"\r\n$tooltip1.SetToolTip($buttonStart, $tipStart)<\/pre>\n<p>To create a ToolTip for another control in the form, you can add another ToolTip or reuse the existing ToolTip. If you reuse the ToolTip, any property changes, such as setting the Active property to $False, affect all instances of the ToolTip.<\/p>\n<p>For example, this script uses the ToolTip in $tooltip1 to create ToolTips for both the Start and Stop buttons.<\/p>\n<pre lang=\"PowerShell\">$tooltip1.SetToolTip($buttonStart, \"To start the task, click Start.\")\r\n$tooltip1.SetToolTip($buttonStop, \"To stop the task, click Stop.\")\r\n<\/pre>\n<p>In contrast, this script uses a separate ToolTip for each of the buttons.<\/p>\n<pre lang=\"PowerShell\">$tooltipButtonStart.SetToolTip($buttonStart, \"To start the task, click Start.\")\r\n$tooltipButtonStop.SetToolTip($buttonStop, \"To stop the task, click Stop.\")\r\n<\/pre>\n<hr \/>\n<hr \/>\n<p><a name=\"Active\"><\/a><\/p>\n<h1>Active property: Turns the ToolTip on and off<\/h1>\n<p>Use this property to disable and enable tooltips.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.active(v=vs.110).aspx\" target=\"_blank\">ToolTip.Active<\/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: <b>$True<\/b><\/li>\n<\/ul>\n<p>For example, this statement disables the ToolTip in $tooltip1.<\/p>\n<pre lang=\"PowerShell\">$tooltip1.Active = $False<\/pre>\n<p><a name=\"AutomaticDelay\"><\/a><\/p>\n<h1>AutomaticDelay property: Determines three tooltip delay property values<\/h1>\n<p>Use this property to coordinate the ToolTip delay property values, instead of setting each delay property individually.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.automaticdelay(v=vs.110).aspx\" target=\"_blank\">ToolTip.AutomaticDelay<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.int32(v=vs.110).aspx\" target=\"_blank\">System.Int32<\/a>: value in milliseconds<\/li>\n<li>Default value: <strong>500<\/strong>(milliseconds)<\/li>\n<\/ul>\n<p>The <em>AutomaticDelay<\/em> property sets the following values:<\/p>\n<ul>\n<li>AutoPopupDelay = AutomaticDelay x 10<\/li>\n<li>InitialDelay = AutomaticDelay<\/li>\n<li>ReshowDelay = AutomaticDelay \/ 5<\/li>\n<\/ul>\n<p><a name=\"InitialDelay\"><\/a><\/p>\n<h1>InitialDelay property: The elapsed time before the ToolTip appears, in milliseconds<\/h1>\n<p>Use this property to determine the number of milliseconds between the time the user hovers places the cursor over the control and the time that the Tooltip appears.<\/p>\n<p>If the delay is too short, the tooltip appears when the user is passing over, not hovering, and becomes annoying. If the delay is too long, the user moves on and does not discover the tooltip.<\/p>\n<p>You can set this delay independently, or use the AutomaticDelay property to coordinate the values of the Tooltip delay properties.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.initialdelay(v=vs.110).aspx\" target=\"_blank\">ToolTip.InitialDelay<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.int32(v=vs.110).aspx\" target=\"_blank\">System.Int32<\/a>: value in milliseconds<\/li>\n<li>Default value: <b>500<\/b> (milliseconds)<\/li>\n<\/ul>\n<p><a name=\"IsBaloon\"><\/a><\/p>\n<h1>IsBalloon property: Determines whether the Tooltip is balloon-shaped or rectangular<\/h1>\n<p>Use the IsBalloon property to change the shape of the Tooltip.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.isballoon(v=vs.110).aspx\" target=\"_blank\">ToolTip.IsBalloon<\/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: <b>$False<\/b><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><em>False<\/em><\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/image6.png\" alt=\"image\" width=\"218\" height=\"34\" border=\"0\" \/><\/p>\n<p><em>True<\/em><\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/image7.png\" alt=\"image\" width=\"197\" height=\"50\" border=\"0\" \/><\/p>\n<p><a name=\"ReshowDelay\"><\/a><\/p>\n<h1>ReshowDelay property: Time between tooltips<\/h1>\n<p>Use the ReshowDelay property to set the length of time, in milliseconds, that elapses before subsequent ToolTip windows appear as the cursor moves from one control to another.<\/p>\n<p>You can set the ReshowDelay property or, to coordinate the Tooltip delays, adjust the AutomaticDelay property.<\/p>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.reshowdelay(v=vs.110).aspx\" target=\"_blank\">ToolTip.ReshowDelay<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.int32(v=vs.110).aspx\" target=\"_blank\">System.Int32<\/a>: value in milliseconds<\/li>\n<li>Default value: <b>100<\/b> (milliseconds)<\/li>\n<\/ul>\n<p><a name=\"ToolTipIcon\"><\/a><\/p>\n<h1>ToolTipIcon property: Adds an icon to the ToolTip text.<\/h1>\n<ul>\n<li>MSDN page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltip.tooltipicon(v=vs.110).aspx\" target=\"_blank\">ToolTip.ToolTipIcon<\/a><\/li>\n<li>Value type: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.tooltipicon(v=vs.110).aspx target=\">System.Windows.Forms.ToolTipIcon<\/a><\/li>\n<li>Default value: <strong>None<\/strong><\/li>\n<\/ul>\n<p>Valid values are:<\/p>\n<blockquote><p><em>Error<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/image8.png\" alt=\"image\" width=\"123\" height=\"41\" border=\"0\" \/><\/p>\n<p><em>Info<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/image9.png\" alt=\"image\" width=\"124\" height=\"41\" border=\"0\" \/><\/p>\n<p><em>None<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/image10.png\" alt=\"image\" width=\"105\" height=\"26\" border=\"0\" \/><\/p>\n<p><em>Warning<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/image11.png\" alt=\"image\" width=\"124\" height=\"41\" border=\"0\" \/><\/p><\/blockquote>\n<p><a name=\"ToolTipTitle\"><\/a><\/p>\n<h1>ToolTipTitle property: Adds a title to the Tooltip window<\/h1>\n<p>Use this property to add, remove, or change the Tooltip title.<\/p>\n<p>For example, this tooltip has the title: ToolTip Title<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/image12.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2014\/01\/image_thumb5.png\" alt=\"image\" width=\"122\" height=\"41\" border=\"0\" \/><\/a><\/p>\n<p><a name=\"SetToolTip\"><\/a><br \/>\n&nbsp;<\/p>\n<h1>SetToolTip method: Associates a ToolTip with a control and sets its text<\/h1>\n<p>Use this method to create a ToolTip for a control or replace the existing tooltip for the control.<\/p>\n<p>SYNTAX:  $tooltip.<b>SetToolTip<\/b>($control, $text)<\/p>\n<p>For example, this statement associates the ToolTip in the $tooltipTest variable with the button in  $button1 and sets its text to &#8220;This is a button&#8221;. <\/p>\n<pre lang=\"PowerShell\">$tooltipTest.SetToolTip($button1, \"This is a button\")<\/pre>\n<p>You can also store the text in a variable and specify the variable in the method call.<\/p>\n<pre lang=\"PowerShell\">$tooltip1Text = \"This is a button\"\r\n$tooltipTest.SetToolTip($button1, $tooltipText)<\/pre>\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":[932,946,703,644,25],"tags":[724,28,1016,865,312],"class_list":["post-6785","post","type-post","status-publish","format-standard","hentry","category-beginners","category-guiprogramming","category-powershell-studio","category-spotlight-on-controls","category-windows-powershell","tag-control","tag-powershell","tag-powershell-studio","tag-tooltip","tag-winforms"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/6785","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=6785"}],"version-history":[{"count":60,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/6785\/revisions"}],"predecessor-version":[{"id":11049,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/6785\/revisions\/11049"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=6785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=6785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=6785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}