{"id":3524,"date":"2011-10-28T09:20:00","date_gmt":"2011-10-28T17:20:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=3524"},"modified":"2011-10-28T09:21:03","modified_gmt":"2011-10-28T17:21:03","slug":"primalforms-2011-spotlight-on-the-tabcontrol","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2011\/10\/28\/primalforms-2011-spotlight-on-the-tabcontrol\/","title":{"rendered":"PrimalForms 2011: Spotlight on the TabControl"},"content":{"rendered":"<p><em>The \u201cSpotlight on Controls\u201d series focuses on a single WinForms control in PrimalForms 2011 , details the important Properties, Methods, and Events of the control and demonstrates how to utilize the control. Most of the information about the controls is still applicable to previous versions of PrimalForms.<\/em><\/p>\n<p>Last time we took a look at the <a href=\"http:\/\/www.sapien.com\/blog\/2011\/09\/27\/primalforms-2011-spotlight-on-the-maskedtextbox-control\/\">MaskedTextBox<\/a> control. This time we will look at the TabControl control:<\/p>\n<p><span style=\"font-size: medium\"><strong>TabControl <\/strong>[System.Windows.Forms.TabControl]<\/span><\/p>\n<p>Manages a related set of tab pages.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"TabControl\" border=\"0\" alt=\"TabControl\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/10\/TabControl.png\" width=\"97\" height=\"19\"><\/p>\n<p>Default Event: SelectedIndexChanged<\/p>\n<p><em>Why use a TabControl control?<\/em><\/p>\n<p>Use the TabControl when you wish to present a series of related controls that are separated into individual pages which can be selected by a tab.<\/p>\n<p><strong><span style=\"font-size: small\"><font size=\"3\"><\/font><\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: small\"><font size=\"3\">Important Properties:<\/font><\/span><\/strong><\/p>\n<p><strong>TabPages<\/strong>  <\/p>\n<p>This property returns the collection of tab pages in this tab control.  <\/p>\n<p>Each tab consists of a TabPage, which acts as a container for other controls that are displayed when the tab is selected.  <\/p>\n<p>TabPage [System.Windows.Forms.TabPage]:<\/p>\n<blockquote>\n<p>Important TabPage Properties:<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"495\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"101\"><strong>Property<\/strong><\/td>\n<td valign=\"top\" width=\"392\">Description<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">Text<\/td>\n<td valign=\"top\" width=\"392\">The text that is displayed on the Tab.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">ToolTipText<\/td>\n<td valign=\"top\" width=\"392\">The text that is displayed in a tooltip when the mouse hovers over the tab (See ShowToolTip property for more info).<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">ImageIndex<\/td>\n<td valign=\"top\" width=\"392\">Sets the image of the tab to the respective image located in the TabControl\u2019s ImageList property.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/blockquote>\n<p>Example of TabPages used to display a set of controls:<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/10\/Sample-Tab-1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Sample Tab 1\" border=\"0\" alt=\"Sample Tab 1\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/10\/Sample-Tab-1_thumb.png\" width=\"244\" height=\"151\"><\/a><\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/10\/Sample-Tab-2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Sample Tab 2\" border=\"0\" alt=\"Sample Tab 2\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/10\/Sample-Tab-2_thumb.png\" width=\"244\" height=\"151\"><\/a><\/p>\n<p>In the designer, you can drag and drop controls directly in the TabPage as you would within the form.<\/p>\n<p><strong>ImageList<\/strong><\/p>\n<p>This property returns or sets the images to display on the control\u2019s tabs. <\/p>\n<p>When an ImageList is set you can use the TabPage\u2019s ImageIndex property to select an image to display on the tab:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Tab Images\" border=\"0\" alt=\"Tab Images\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/10\/Tab-Images.png\" width=\"203\" height=\"76\"><\/p>\n<p>See the <a href=\"http:\/\/www.sapien.com\/blog\/2011\/10\/19\/primalforms-2011-spotlight-on-the-imagelist-control\/\">PrimalForms 2011: Spotlight of the ImageList Control<\/a> blog article for more details on how to use an ImageList.<\/p>\n<p><strong><\/strong>&nbsp;<\/p>\n<p><strong>SelectedTab<\/strong><\/p>\n<p>This property returns or sets the currently selected tab page.<\/p>\n<p>You can use this property to programmatically change the current tab:<\/p>\n<pre><span style=\"color: #8b0000\">$tabcontrol1<\/span><span style=\"color: #000000\">.SelectedTab <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$tabpageProcess<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>SelectedIndex<\/strong><\/p>\n<p>This property returns or sets the index of the currently selected tab page. <\/p>\n<p>SelectedIndex is similar to the SelectedTab but instead it uses the index of the tab to determine which tab is selected. <\/p>\n<pre><span style=\"color: #8b0000\">$tabcontrol1<\/span><span style=\"color: #000000\">.SelectedIndex <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">0<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #008000\">#Select the first tab<\/span><\/pre>\n<p><strong><\/strong>&nbsp;<\/p>\n<p><strong>ShowToolTip<\/strong><\/p>\n<p>This property indicates whether ToolTips should be shown for tabs that have their ToolTips set. Set the ShowToolTip property to <em>True<\/em> to enable ToolTips.<\/p>\n<p>Default Value: <em>False<\/em><\/p>\n<p>You must set each TabPage\u2019s ToolTipText property in order for the tooltip to display when the mouse hovers over the tab. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Tab ToolTip\" border=\"0\" alt=\"Tab ToolTip\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/10\/Tab-ToolTip.png\" width=\"176\" height=\"89\"><\/p>\n<p><font size=\"3\"><strong><\/strong><\/font>&nbsp;<\/p>\n<p><font size=\"3\"><strong>Important Events:<\/strong><\/font><\/p>\n<p><strong>SelectedIndexChanged<\/strong><\/p>\n<p>This event occurs when the value of the SelectedIndex property changes.<\/p>\n<p>Use this event if you wish to respond when the current tab is changed. For example, you could use this event to trigger data validation or enable or disable certain controls that depend upon the current tab.<\/p>\n<p>Note: Pressing Ctrl + Tab will select the next TabPage in the TabControl.<\/p>\n<pre><span style=\"color: #8b0000\">$tabcontrol1_SelectedIndexChanged<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">{\n    \n    <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$tabcontrol1<\/span><span style=\"color: #000000\">.SelectedTab <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$tabpageProcess<\/span><span style=\"color: #000000\">)\n    {\n        <\/span><span style=\"color: #008000\">#We are on the process tab    <\/span><span style=\"color: #000000\">\n    }\n    <\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #000000\">\n    {\n        <\/span><span style=\"color: #008000\">#We are on another tab    <\/span><span style=\"color: #000000\">\n    }\n    \n}<\/span><\/pre>\n<p>Another example can be found in the Tab Control Form Template for PrimalForms 2011 which utilizes the SelectedIndexChanged event to the&nbsp; update navigation buttons:<\/p>\n<pre><span style=\"color: #8b0000\">$tabcontrol1_SelectedIndexChanged<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">{\n    \n    <\/span><span style=\"color: #8b0000\">$buttonNext<\/span><span style=\"color: #000000\">.Enabled <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$tabcontrol1<\/span><span style=\"color: #000000\">.SelectedIndex <\/span><span style=\"color: #0000ff\">-lt<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$tabcontrol1<\/span><span style=\"color: #000000\">.TabCount <\/span><span style=\"color: #0000ff\">-<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">1<\/span><span style=\"color: #000000\">    \n    <\/span><span style=\"color: #8b0000\">$buttonPrev<\/span><span style=\"color: #000000\">.Enabled <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$tabcontrol1<\/span><span style=\"color: #000000\">.SelectedIndex <\/span><span style=\"color: #0000ff\">-gt<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">0<\/span><span style=\"color: #000000\">\n}<\/span><\/pre>\n<p>This form template serves as a good starting point when you need a form that requires a TabControl.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The \u201cSpotlight on Controls\u201d series focuses on a single WinForms control in PrimalForms 2011 , details the important Properties, Methods, and Events of the control and demonstrates how to utilize the control. Most of the information about the controls is still applicable to previous versions of PrimalForms. Last time we took a look at the [&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":[509,575,644,25],"tags":[641,28,633,689,327],"class_list":["post-3524","post","type-post","status-publish","format-standard","hentry","category-primalforms-software-news","category-primalforms-2011-software-news","category-spotlight-on-controls","category-windows-powershell","tag-controls","tag-powershell","tag-primalforms-2011","tag-tabcontrol","tag-winform"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3524","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=3524"}],"version-history":[{"count":1,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3524\/revisions"}],"predecessor-version":[{"id":3525,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3524\/revisions\/3525"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=3524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=3524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=3524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}