Working with RadioButton Controls


Working with RadioButton Controls

Radio button controls are commonly presented to give users an array of choices that are mutually exclusive. When a radio button within a group is selected, the others clear automatically. Radio buttons are considered to be in the same group if they are in the same container. An application can have multiple radio button groups by putting radio buttons in different Panel controls (see the "Using the Panel Control" section for a description of the Panel class).

SHOP TALK: HANDLING THE SOFT INPUT PANEL

The InputPanel control corresponds to the SIP on the Pocket PC OS. This control provides the ability to display and hide the SIP. The InputPanel exposes the Enabled property. If the property is set to true, the SIP is displayed; setting the property to false hides the SIP.

Some TextBox controls would be hidden when the SIP appears. The Pocket PC application design guidelines suggest that these controls should be moved so that they remain visible. To help achieve this, the InputPanel control will raise the EnabledChanged event when the Enabled property changes. You should handle this event and move the TextBox above the SIP when the Enabled property is set to true. When the Enabled property is set to false, the TextBox controls should be moved back to their original positions .


The RadioButton class publishes two events that are fired when the checked state of a RadioButton changes: Click and CheckedChanged . The Click event is raised when a user clicks the radio button with the stylus. You can handle this Click event just as you handled the Click event for the Button class (see the "Handling a ToolBar's ButtonClick Event" section). The CheckedChanged event is raised when the RadioButton 's checked state changes, either programmatically or graphically.

The Click event will not be raised if the RadioButton 's Checked property is changed programmatically. The Arnie.exe application demonstrates how to use a group of RadioButton controls. (You can find the code for this application in this book's Arnie sample program.) Figure 3.7 shows the application running in the Pocket PC emulator. The application is a simple trivia question about the name of the first movie Arnold Schwarzenegger ever starred in.

Figure 3.7. The Arnie application running on the Pocket PC 2002 emulator.

graphics/03fig07.jpg

When a movie is selected, the application traps the RadioButton 's CheckedChanged event, and a message box is displayed if the correct RadioButton is checked. The following code demonstrates how to handle the CheckedChanged event for an incorrect answer (I don't want to give away the correct answer).

 
 C# private void radioButton2_CheckedChanged(object sender,         System.EventArgs e) {   if(this.radioButton2.Checked)     MessageBox.Show       ("Wrong, The Terminator (1984) O.J Simpson almost got the role...",               "Wrong!"); } VB Private Sub radioButton2_CheckedChanged(ByVal sender As System.Object,         ByVal e As System.EventArgs) Handles radioButton2.CheckedChanged   If radioButton2.Checked Then     MessageBox.Show       ("Wrong, The Terminator (1984) O.J Simpson almost got the role...",               "Wrong!")   End If End Sub 


Microsoft.NET Compact Framework Kick Start
Microsoft .NET Compact Framework Kick Start
ISBN: 0672325705
EAN: 2147483647
Year: 2003
Pages: 206

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net