|
-
Jul 28th, 2008, 12:01 AM
#1
Thread Starter
New Member
[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!!
-
Jul 28th, 2008, 12:39 AM
#2
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.
-
Jul 28th, 2008, 12:47 AM
#3
Re: [2008] No display with pic object
you're assigning empty values to your percent array
vb Code:
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 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 percent() As Single = {housingP, transportP, foodP, otherP}
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 28th, 2008, 01:09 AM
#4
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|