Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  Chart Success: Second Helpings of Pie. Part 3  »  The User Input Controls
 »  Home  »  Windows Development  »  Graphics  »  Chart Success: Second Helpings of Pie. Part 3  »  The User Input Controls
Chart Success: Second Helpings of Pie. Part 3
by Ged Mead | Published  03/23/2005 | .NET Newbie Graphics | Rating:
The User Input Controls


 


TextBox
    Ignoring labels, the first control on the form is a TextBox. If creating your own project, you should name it txtName.


NumericUpDown
    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 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).

      The following code will take the user's color choice :

    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 
      End If       
    End Sub  


"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))     
          cboPattern.Items.AddRange(patts) 
    End Sub
  

         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), _     
                cboPattern.Text), HatchStyle)     

    End Sub
 

       Effectively, it checks the user's choice - which is a string type in the combobox -   finds the equivalent HatchStyle enumeration and stores it.  

 

 

Comments    Submit Comment

Comment #1  (Posted by an unknown user on 03/25/2005)
Rating
The good is getting even better. Cool job, Ged.
 
Comment #2  (Posted by an unknown user on 04/19/2005)
Rating
an amazing series of articles! It difficult to explain in such a simple way has you did. Thanks
 
Comment #3  (Posted by Ronan on 04/13/2006)
Rating
Hi i have read these tutorials and am looking your help.
I am trying to develop a pie chart interface in Visual Studio 2003 for a PDA (Smart Device Application) and tried your code. however it is not compatible as it does not recognise the drawPie and FillPie commands, etc. Do you have an example i could use to help me for this?
Thank you, Ronan
 
Comment #4  (Posted by PeteB on 05/22/2006)
Rating
reall useful.
 
Comment #5  (Posted by an unknown user on 12/08/2006)
Rating
Very Educative
 
Comment #6  (Posted by an unknown user on 08/27/2007)
Rating
clear / simple
 
Sponsored Links