Ignoring labels, the first control on the form is a TextBox. If creating your own project, you should name it txtName.
The next control is a NumericUpDown, named nudValue. You can set the Min, Max and Value settings to whatever values you like.
"Select Color" Button
Next down the form is a Button. I have named it btnColor, but the name isn't important.
ColorDialog The following code will take the user's color choice :
The button's click event will open a ColorDialog from which the user can select a forecolor for the HatchStyle.
Add a ColorDialog to your Form if necessary (one has already been included in the Skeleton Solution provided).
Private Sub btnColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnColor.Click
' Get user's choice of color
Dim ColorPicker As New ColorDialog
Dim Choice As DialogResult = ColorPicker.ShowDialog
If Choice <> DialogResult.Cancel Then
clrPicked = ColorPicker.Color
"Select Pattern" ComboBox
The fourth user input control is a ComboBox, which should be named cboPattern.
This ComboBox allows the user to select any of the HatchStyles for use in the pie chart. We therefore need to populate the combo with that list. Fortunately VB.Net gives us an extremely easy way of doing this.
Put this code in the Form_Load event to get each of the HatchStyle names and populate the ComboBox with them:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Populate the combobox with all available HatchStyles
Dim patts() As String
patts = System.Enum.GetNames(GetType(HatchStyle))
The ability to get at these Enumerations and manipulate them as a range can be very useful. The alternative of manually typing each of them in as an "Items.Add" code line isn't appealing!
Now the user can select a HatchStyle from the ComboBox and when this happens we note the user's choice in the variable we created for this purpose earlier on, named Hatchpicked. This code in the ComboBox's SelectedIndexChanged event does exactly that:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPattern.SelectedIndexChanged
hatchPicked = CType(System.Enum.Parse(GetType(HatchStyle), _
Effectively, it checks the user's choice - which is a string type in the combobox - finds the equivalent HatchStyle enumeration and stores it.