Compunet Corporation Programming with Visual Basic.NET GUI Chapter 3 Week 13 Tariq Aziz and Kevin Jones
Compunet Corporation Overview Chapter 3 is about using Toolbox controls in Visual Studio.NET. Some common Toolbox controls are: –TextBox –Button –CheckBox –RadioButton –ListBox –ComboBox –DateTimePicker –LinkLabel
Compunet Corporation TextBox The TextBox control provides a way for your program to get text input from the user. He simply types text in the textbox. The text entered by the user is stored in the Text property of the Textbox. You can access it as follows TextBox1.Text
Compunet Corporation TextBox Control
Compunet Corporation Button The Button control provides a way for your program to get click input from the user. He simply clicks a button when he wants to initiate some response from the program. The text displayed inside the button is stored in the Text property of the Button, which is usually defined by the programmer through the Properties window at design time. When the user clicks the button at runtime, the corresponding event procedure is invoked, which will perform the actions associated with the button. By default, the name of the event procedure is the concatenation of the name of the button with the string “_Click”, e.g. Button1_Click() for Button1.
Compunet Corporation Button Control Double-click the button to go to its event procedure.
Compunet Corporation Button1_Click Event Procedure
Compunet Corporation CheckBox The CheckBox control provides a way for your program to get on/off input from the user. The checkbox is a toggle switch; the user clicks in the checkbox to turn it off or on. A group of checkboxes allows the user to select zero or more choices from the group. Selection of one checkbox of a group is independent of the other checkboxes (see radio buttons for contrast). The Checked property stores the on/off state of the checkbox. If the user has checked the checkbox, Checked = True; otherwise, it is False. You can access the Checked property as follows: CheckBox1.Checked
Compunet Corporation CheckBox Control
Compunet Corporation RadioButton The RadioButton control provides a way for your program to get on/off input from the user. The radio button is a toggle switch; the user clicks in the radio button to turn it off or on. A group of radio buttons allows the user to select exactly one choice from the group. The difference between the behavior of a radio button and a checkbox is that when the user clicks a radio button, all other radio buttons in the same group are turned off. The Checked property stores the on/off state of the radio button. If the user has selected the radio button, Checked = True; otherwise, it is False. You can access the Checked property as follows: RadioButton1.Checked
Compunet Corporation RadioButton Control
Compunet Corporation ListBox The ListBox control provides a way for your program to allow the user to choose an item from a list. He simply clicks on the item in the ListBox to select it. All items in the list box appear on the form. The Items property stores the list of items contained in the listbox. There are two ways to define the items in the listbox: – You can click the ellipsis button (…) just to the right of the Items property value in the Properties window to define the list of items at design time, or – You can invoke methods at runtime to add items to the Items list: e.g. ListBox1.Items.Add(“Saudi Riyals”)
Compunet Corporation ListBox Control
Compunet Corporation ListBox.SelectedIndex The SelectedIndex property of the list box stores the index of the list item that was selected by the user. ListBox1.SelectedIndex SelectedIndex counting starts at 0. For example, say we have a list of five items: US Dollar, Saudi Riyal, British Pound, Japanese Yen, and Euro. Each item would have indices 0, 1, 2, 3, and 4, respectively. For example, if the user selects British Pound, the SelectedIndex property of the ListBox would be set to 2.
Compunet Corporation ComboBox The ComboBox control provides a way for the user to select an item from a list. It’s very similar to a ListBox, except that the whole list is not displayed directly on the form. Instead, the list is only displayed when the user clicks the drop-down arrow. Once the user makes his selection, the selection is displayed in the combo box on the form. For this reason, the combo box is also called a drop-down listbox. The combo box also has a SelectedIndex property, which stores the index of the selected item.
Compunet Corporation ComboBox Control
Compunet Corporation Programming Exercise Write a small currency converter that converts between U.S. Dollars, British Pounds, Saudi Riyals, Japanese Yen, and Euros. Your form should contain at least one text box (to get the amount of money in the first currency), two list boxes (to select the first and second currencies), a label (to display the equivalent amount of money in the second currency), and two buttons: Convert and Quit.