Results 1 to 4 of 4

Thread: [RESOLVED] [2008] No display with pic object

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    6

    Resolved [RESOLVED] [2008] No display with pic object

    hello,

    i was wondering if anyone could help me with an issue i have with my program. i am trying to create a program that displays a pie chart after the user inputs the numeric values for the sectors of the pies. I get output of the legend, but not the actual pie itself.

    Code:

    Public Class frmBudget

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
    Dim housing As Single = 0, transport As Single = 0, _
    food As Single = 0, other As Single = 0
    Dim sum As Single = 0
    Dim housingP As Single = 0, transportP As Single = 0, _
    foodP As Single = 0, otherP As Single = 0
    Dim percent() As Single = {housingP, transportP, foodP, otherP}
    Dim legend() As String = {"Housing", "Transportation", "Food", "Other"}

    housing = CSng(txtHousing.Text)
    transport = CSng(txtTransportation.Text)
    food = CSng(txtFood.Text)
    other = CSng(txtOther.Text)
    sum = housing + transport + food + other
    housingP = housing / sum
    transportP = transport / sum
    foodP = food / sum
    otherP = other / sum

    Dim pie As Graphics = picPieChart.CreateGraphics
    Dim r As Integer = 115 ' circle radius
    Dim c As Integer = 120 'circle center has coordinates (c, c)
    Dim sumOfSweepAngles As Single = 0
    Dim brush() As Brush = {Brushes.Blue, Brushes.Red, Brushes.Green, Brushes.Yellow}

    For i As Integer = 0 To 3
    pie.FillPie(brush(i), c - r, c - r, 2 * r, 2 * r, _
    sumOfSweepAngles, percent(i) * 360)
    sumOfSweepAngles += percent(i) * 360
    pie.FillRectangle(brush(i), 350, 20 + 30 * i, 20, 20)
    pie.DrawString(legend(i), Me.Font, Brushes.Black, 380, 22 + 30 * i)
    Next
    End Sub
    End Class

    thanks in advance to anyone who can help!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] No display with pic object

    First up, you shouldn't be doing any drawing in the Button's Click event handler. All drawing should be done in the Paint event handler of the control you're drawing on.

    As for your question, I haven't actually looked at your code but, in order to make your app more OO, you might like to have a look at this thread. A pie chart would actually be a simplification of that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2008] No display with pic object

    you're assigning empty values to your percent array

    vb Code:
    1. Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
    2.        
    3.         Dim housing As Single = 0, transport As Single = 0, _
    4.         food As Single = 0, other As Single = 0
    5.         Dim sum As Single = 0
    6.         Dim housingP As Single = 0, transportP As Single = 0, _
    7.         foodP As Single = 0, otherP As Single = 0
    8.  
    9.         Dim legend() As String = {"Housing", "Transportation", "Food", "Other"}
    10.  
    11.         housing = CSng(txtHousing.Text)
    12.         transport = CSng(txtTransportation.Text)
    13.         food = CSng(txtFood.Text)
    14.         other = CSng(txtOther.Text)
    15.         sum = housing + transport + food + other
    16.         housingP = housing / sum
    17.         transportP = transport / sum
    18.         foodP = food / sum
    19.         otherP = other / sum
    20.  
    21.         Dim percent() As Single = {housingP, transportP, foodP, otherP}
    22.  
    23.         Dim pie As Graphics = picPieChart.CreateGraphics
    24.         Dim r As Integer = 115 ' circle radius
    25.         Dim c As Integer = 120 'circle center has coordinates (c, c)
    26.         Dim sumOfSweepAngles As Single = 0
    27.         Dim brush() As Brush = {Brushes.Blue, Brushes.Red, Brushes.Green, Brushes.Yellow}
    28.  
    29.         For i As Integer = 0 To 3
    30.             pie.FillPie(brush(i), c - r, c - r, 2 * r, 2 * r, _
    31.             sumOfSweepAngles, percent(i) * 360)
    32.             sumOfSweepAngles += percent(i) * 360
    33.             pie.FillRectangle(brush(i), 350, 20 + 30 * i, 20, 20)
    34.             pie.DrawString(legend(i), Me.Font, Brushes.Black, 380, 22 + 30 * i)
    35.         Next
    36. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    6

    Re: [2008] No display with pic object

    thanks for the help.. i needed to move the line holding the percent array below where the percent variables were declared!

    Thanks to both of you for the help and advice..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width