- Investigating Unsupported Controls in the .NET Compact Framework
- Investigating Unsupported System.Windows.Forms Functionality in the .NET Compact Framework
- Working with the Visual Studio .NET Form Designer
- Understanding the Different Windows Forms Target Platforms
- Working with the Form Control
- Programming the Button Control
- Using the TextBox Control
- Using the Label Control
- Working with RadioButton Controls
- Using the CheckBox Control
- Using the ComboBox Control
- Using the ListBox Control
- Using the NumericUpDown Control
- Using the DomainUpDown Control
- Programming the ProgressBar Control
- Using the StatusBar Control
- Using the TrackBar Control
- Using the ToolBar Control
- Adding Menus with the MainMenu Control
- Using a ContextMenu Control in an Application
- Using the Timer Control
- Using the OpenFileDialog and SaveFileDialog Controls
- Using the Panel Control
- Using the HScrollBar and VScrollBar Controls
- Using the ImageList Control
- Using the PictureBox Control
- Using the ListView Control
- Using the TabControl Control
- Using the TreeView Control
- Working with the DataGrid Control
- In Brief
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).
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.
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