{"id":5625,"date":"2013-02-12T09:29:00","date_gmt":"2013-02-12T17:29:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=5625"},"modified":"2013-02-12T09:29:55","modified_gmt":"2013-02-12T17:29:55","slug":"powershell-studio-enable-and-disable-groups-of-controls","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2013\/02\/12\/powershell-studio-enable-and-disable-groups-of-controls\/","title":{"rendered":"PowerShell Studio: Enable and Disable Groups of Controls"},"content":{"rendered":"<p>If you follow the <a href=\"http:\/\/www.sapien.com\/blog\/topics\/spotlight-on-controls\/\">Spotlight on Controls<\/a> series you might be familiar with the Enable property that is shared by all WinForms controls. This property allows you to disable controls so they no longer can be interacted with. <\/p>\n<p>For example, after pressing a button that triggers a Job, it is necessary to disable the button in order to prevent the user from pressing it again until the Job completes. Some instances might require you to disable a group of controls. In this case, your code may look like the following:<\/p>\n<pre><span style=\"color: #8b0000\">$buttonAdd<\/span><span style=\"color: #000000\">.Enable <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$false<\/span><span style=\"color: #000000\">\n<\/span><span style=\"color: #8b0000\">$buttonRemove<\/span><span style=\"color: #000000\">.Enable <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$false<\/span><span style=\"color: #000000\">\n<\/span><span style=\"color: #8b0000\">$comboBoxOptions<\/span><span style=\"color: #000000\">.Enable <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$false<\/span><\/pre>\n<p>This list of controls can get rather long, especially when working with a large group of controls. <\/p>\n<p>The good news is WinForms provides an easy alternative for disabling a group of controls and this can be accomplished by using container controls. A container control is a control that allows you to place other controls within it. Examples of container controls include:<\/p>\n<p>GroupBox<br \/>Panel<br \/>TabControl<br \/>TableLayoutPanel<\/p>\n<p>&nbsp;<\/p>\n<p>Once you have decided which container control to use, simply place all the controls you wish to enable \/ disable within the container. In this case I used a GroupBox to group my controls:<\/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=\"GroupBox of Controls\" border=\"0\" alt=\"GroupBox of Controls\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/01\/GroupBox-of-Controls.png\" width=\"283\" height=\"186\"><\/p>\n<p>Now when you need to disable the controls, you simply set the GroupBox\u2019s Enable property to <em>False<\/em> and all the controls contained within will be disabled.<\/p>\n<pre><span style=\"color: #8b0000\">$buttonDisableGroup_Click<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">{\n    <\/span><span style=\"color: #8b0000\">$groupbox1<\/span><span style=\"color: #000000\">.Enabled <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$false<\/span><span style=\"color: #000000\">\n}<\/span><\/pre>\n<p><font color=\"#ff0000\"><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=\"Disabled Groupbox\" border=\"0\" alt=\"Disabled Groupbox\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/01\/Disabled-Groupbox.png\" width=\"283\" height=\"186\"><\/font><\/p>\n<p><font color=\"#ff0000\">WARNING:<\/font> It is not recommended using the Form\u2019s Enable property. Doing so will result in an unresponsive window and will prevent you from interacting with the GUI. In other words, you will not be able to move, resize, or exit the form. <\/p>\n<p>You can download the <a href=\"http:\/\/www.sapien.com\/downloads#Sample Scripts\/EnableDisableControls.zip\">Enable and Disable Controls Sample<\/a> from our <a href=\"http:\/\/sapien.com\/downloads\">Downloads<\/a> section under Sample Scripts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you follow the Spotlight on Controls series you might be familiar with the Enable property that is shared by all WinForms controls. This property allows you to disable controls so they no longer can be interacted with. For example, after pressing a button that triggers a Job, it is necessary to disable the button [&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,705,509],"tags":[641,28,1016,314,312],"class_list":["post-5625","post","type-post","status-publish","format-standard","hentry","category-howto","category-powershell-studio-2012","category-primalforms-software-news","tag-controls","tag-powershell","tag-powershell-studio","tag-primalforms","tag-winforms"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/5625","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=5625"}],"version-history":[{"count":6,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/5625\/revisions"}],"predecessor-version":[{"id":5653,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/5625\/revisions\/5653"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=5625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=5625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=5625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}