- 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
Programming the Button Control
The System.Windows.Forms.Button class is the .NET implementation of a button control. When the user clicks the button with the stylus, a Click event is raised.
You can handle this event by implementing a System.EventHandler delegate. The code that follows is an implementation of the EventHandler that displays the current time.
C# Private void button_Click(object sender, System.EventArgs e) { MessageBox.Show(DateTime.Now.ToShortTimeString(), "The Current Time Is", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } VB Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show(DateTime.Now.ToShortTimeString(), "The Current Time Is", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) End Sub
Figure 3.6 shows the GiveEmTime.exe running on the Pocket PC emulator. The button labeled What is the Time has been clicked, and the current time is being displayed in the dialog box.
Figure 3.6 The GiveEmTime application running on the Pocket PC 2002 emulator.
Table 3.4 The KeyCodes Generated by the Directional Pad on a Pocket PC Device
KeyCode Value |
Associated Hardware Button |
Keys.Up |
The top of the pad was pressed. |
Keys.Down |
The bottom of the pad was pressed. |
Keys.Left |
The left side of the pad was pressed. |
Keys.Right |
The right side of the pad was pressed. |
Keys.Return |
The center of the pad was pressed. |