{"id":3183,"date":"2011-07-08T10:58:00","date_gmt":"2011-07-08T18:58:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=3183"},"modified":"2011-07-08T10:59:01","modified_gmt":"2011-07-08T18:59:01","slug":"primalforms-2011-spotlight-on-the-radiobutton-control","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2011\/07\/08\/primalforms-2011-spotlight-on-the-radiobutton-control\/","title":{"rendered":"PrimalForms 2011: Spotlight on the RadioButton Control"},"content":{"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.<\/p>\n<p>Last time we took a look at the <a href=\"http:\/\/www.sapien.com\/blog\/2011\/06\/29\/primalforms-2011-spotlight-on-the-checkbox-control\/\">CheckBox<\/a> control. This time we will look at the RadioButton control:<\/p>\n<p><span style=\"font-size: medium\"><strong>RadioButton Control <\/strong>[System.Windows.Forms.RadioButton]<\/span><\/p>\n<p>Enables the user to select a single option from a group of choices when paired with other radio buttons.<\/p>\n<p>Default Event: CheckChanged<\/p>\n<p><em>Why use a RadioButton control?<\/em><\/p>\n<p>Use a radio button when you want to present users with a multiple choices, but only allow them to select one option. Radio buttons behave similar to a CheckBox Control, except that they work in conjunction with other radio buttons.<\/p>\n<p><strong>Grouping Radio Buttons:<\/strong><\/p>\n<p>By default radio buttons group with any other radio button located in the same container. Usually the container consists of the Form\u2019s client area, but there are other controls you can use to group radio buttons:<\/p>\n<p>Group Boxes:<\/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\" border=\"0\" alt=\"GroupBox\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/GroupBox.png\" width=\"385\" height=\"225\"><\/p>\n<p>Panels:<\/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=\"Panel\" border=\"0\" alt=\"Panel\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Panel.png\" width=\"385\" height=\"225\"><\/p>\n<p>Without using a container, the user will only be able to select a single option out of all the radio buttons, essentially creating one large group of options.<\/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=\"No Containers\" border=\"0\" alt=\"No Containers\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/No-Containers.png\" width=\"385\" height=\"225\"><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"font-size: small\"><font size=\"3\">Important Properties:<\/font><\/span><\/strong><\/p>\n<p><strong>Checked<\/strong><\/p>\n<p>Indicates whether the radio button is checked or not.<\/td>\n<p><em>Why use the Checked property?<\/em>  <\/p>\n<p>Use the Checked property to determine the state of a specific radio button or when you want to check or uncheck a radio button.&nbsp; When you set this property to True, the previously checked radio button in the group will be unchecked.<\/p>\n<p>Values (Default: <em>False<\/em>):<\/p>\n<blockquote>\n<p><em>True \/ False<\/em><\/p>\n<\/blockquote>\n<p>Setting the Checked property in the script editor:<\/p>\n<pre><span style=\"color: #8b0000\">$radiobutton1<\/span><span style=\"color: #000000\">.Checked <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$true<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><strong><font size=\"3\">Important Events:<\/font><\/strong><\/p>\n<p><strong>CheckChanged<\/strong> <\/p>\n<p>Occurs whenever the Checked property changes value. <\/p>\n<p><em>Why use the CheckChanged event?<\/em> <\/p>\n<p>Use the CheckChanged property when you wish to respond to the user checking a radio button. This event also fires when the previously checked radio button is unchecked due to the user checking a different radio button. <\/p>\n<p>The following is an example of the CheckChanged event. In this example, a label is set with the radio button\u2019s text to inform the user when a radio button option is checked. We set the same CheckChanged event for all the radio buttons and use the <span style=\"color: #8b0000\">$this <\/span>variable to access the radio button that triggered the event.&nbsp; <\/p>\n<\/td>\n<pre><span style=\"color: #8b0000\">$radiobutton_CheckedChanged<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">{\n    <\/span><span style=\"color: #008000\">#Use the $this variable to access the calling control<\/span><span style=\"color: #000000\">\n    <\/span><span style=\"color: #008000\">#Only set the Label if this radio button is checked    <\/span><span style=\"color: #000000\">\n    <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$this<\/span><span style=\"color: #000000\">.Checked <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$true<\/span><span style=\"color: #000000\">)\n    {\n        <\/span><span style=\"color: #008000\">#Use the Radio Button's Text to set the label<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #8b0000\">$labelSelected<\/span><span style=\"color: #000000\">.Text <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$this<\/span><span style=\"color: #000000\">.Text    \n    }\n}<\/span><\/pre>\n<p>Now when the user checks a radio button, the name (Text property) of the radio button will be displayed.<\/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=\"Display Checked Radio Name\" border=\"0\" alt=\"Display Checked Radio Name\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Display-Checked-Radio-Name.png\" width=\"385\" height=\"225\"><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Next on Spotlight on Controls:<\/strong><\/p>\n<p>The ProgressBar control.<\/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":[575,644,25],"tags":[641,28,633,662,327],"class_list":["post-3183","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-radiobutton","tag-winform"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3183","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=3183"}],"version-history":[{"count":2,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3183\/revisions"}],"predecessor-version":[{"id":3185,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3183\/revisions\/3185"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=3183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=3183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=3183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}