locked
Clickable Pie Chart (windows form) RRS feed

  • Question

  • I have been able to make some dynamic pie charts. The pie charts are created on form load and are databind to a table. Now I would like to be able to click on the pie charts to open another windows form. I have searched a bit and every where they say to use the mouse down event.. the problem is that I am creating the pie chart with code and therefore when I use the:

    Private Sub Chart1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseDown  

     

    I'm getting the error:

    Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

    because obviously there is no chart 1 on the design form.
    Any help would be appreciated.

     

    Thursday, February 2, 2012 8:24 AM

Answers

  • ...

     the problem is that I am creating the pie chart with code and therefore when I use the:

    Private Sub Chart1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseDown  

     

    I'm getting the error:

    Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

    because obviously there is no chart 1 on the design form.

    Hi,

    but somewhere in code you do declare the Chart-object... so use the WithEvents keyword there (like private WithEvents chart1 as new Chart() ) or add a Handler for the event.

    Regards,

      Thorsten


    • Edited by Thorsten Gudera Thursday, February 2, 2012 4:36 PM
    • Proposed as answer by jwavila Friday, February 3, 2012 7:15 AM
    • Marked as answer by Mansin Wednesday, February 8, 2012 7:45 AM
    Thursday, February 2, 2012 4:36 PM

All replies

  • Hello,

    Try the link below it might help you.

    http://www.codeproject.com/Articles/31397/New-Microsoft-Chart-Controls-for-Web-and-Windows-F

    Thursday, February 2, 2012 11:44 AM
  • ...

     the problem is that I am creating the pie chart with code and therefore when I use the:

    Private Sub Chart1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseDown  

     

    I'm getting the error:

    Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

    because obviously there is no chart 1 on the design form.

    Hi,

    but somewhere in code you do declare the Chart-object... so use the WithEvents keyword there (like private WithEvents chart1 as new Chart() ) or add a Handler for the event.

    Regards,

      Thorsten


    • Edited by Thorsten Gudera Thursday, February 2, 2012 4:36 PM
    • Proposed as answer by jwavila Friday, February 3, 2012 7:15 AM
    • Marked as answer by Mansin Wednesday, February 8, 2012 7:45 AM
    Thursday, February 2, 2012 4:36 PM
  • hmm yeah.. here's my code.. sorry for late reply.. i got depressed because of this =.=



                        Dim Chart1 As Chart = New Chart()
                        Dim ChartArea1 As ChartArea = New ChartArea()
                        Dim Series1 As Series = New Series()

                        TableLayoutPanel1.Controls.Add(Chart1)
                       

    • Edited by Mansin Friday, February 3, 2012 7:13 AM
    Friday, February 3, 2012 6:23 AM
  • as Thorsten said, declare your Chart object using WithEvents. Then you will have the Chart in the object dropdown on the left side of the code editor window, and the events for that object in the right dropdown

    WithEvents Chart1 As Chart
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Chart1 = New Chart()
    
        End Sub
    

     

     

    Friday, February 3, 2012 7:14 AM