Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnChart As System.Windows.Forms.Button
Friend WithEvents lblInfo As System.Windows.Forms.Label
Friend WithEvents tx1 As System.Windows.Forms.TextBox
Friend WithEvents tx2 As System.Windows.Forms.TextBox
Friend WithEvents tx3 As System.Windows.Forms.TextBox
Friend WithEvents tx4 As System.Windows.Forms.TextBox
Friend WithEvents lblPie As System.Windows.Forms.Label
Friend WithEvents lblPercent As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnChart = New System.Windows.Forms.Button
Me.lblInfo = New System.Windows.Forms.Label
Me.tx1 = New System.Windows.Forms.TextBox
Me.tx2 = New System.Windows.Forms.TextBox
Me.tx3 = New System.Windows.Forms.TextBox
Me.tx4 = New System.Windows.Forms.TextBox
Me.lblPie = New System.Windows.Forms.Label
Me.lblPercent = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'btnChart
'
Me.btnChart.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(128, Byte))
Me.btnChart.Location = New System.Drawing.Point(24, 104)
Me.btnChart.Name = "btnChart"
Me.btnChart.Size = New System.Drawing.Size(104, 24)
Me.btnChart.TabIndex = 0
Me.btnChart.Text = "Chart"
'
'lblInfo
'
Me.lblInfo.Location = New System.Drawing.Point(16, 24)
Me.lblInfo.Name = "lblInfo"
Me.lblInfo.Size = New System.Drawing.Size(96, 24)
Me.lblInfo.TabIndex = 1
Me.lblInfo.Text = "Enter four values:"
Me.lblInfo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'tx1
'
Me.tx1.Location = New System.Drawing.Point(128, 24)
Me.tx1.Name = "tx1"
Me.tx1.Size = New System.Drawing.Size(112, 20)
Me.tx1.TabIndex = 2
Me.tx1.Text = "10"
'
'tx2
'
Me.tx2.Location = New System.Drawing.Point(248, 24)
Me.tx2.Name = "tx2"
Me.tx2.Size = New System.Drawing.Size(112, 20)
Me.tx2.TabIndex = 3
Me.tx2.Text = "20"
'
'tx3
'
Me.tx3.Location = New System.Drawing.Point(368, 24)
Me.tx3.Name = "tx3"
Me.tx3.Size = New System.Drawing.Size(112, 20)
Me.tx3.TabIndex = 4
Me.tx3.Text = "30"
'
'tx4
'
Me.tx4.Location = New System.Drawing.Point(488, 24)
Me.tx4.Name = "tx4"
Me.tx4.Size = New System.Drawing.Size(112, 20)
Me.tx4.TabIndex = 5
Me.tx4.Text = "40"
'
'lblPie
'
Me.lblPie.Location = New System.Drawing.Point(248, 80)
Me.lblPie.Name = "lblPie"
Me.lblPie.Size = New System.Drawing.Size(301, 301)
Me.lblPie.TabIndex = 6
'
'lblPercent
'
Me.lblPercent.Location = New System.Drawing.Point(128, 56)
Me.lblPercent.Name = "lblPercent"
Me.lblPercent.Size = New System.Drawing.Size(472, 16)
Me.lblPercent.TabIndex = 7
'
'Form1
'
Me.AcceptButton = Me.btnChart
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 405)
Me.Controls.Add(Me.lblPercent)
Me.Controls.Add(Me.lblPie)
Me.Controls.Add(Me.tx4)
Me.Controls.Add(Me.tx3)
Me.Controls.Add(Me.tx2)
Me.Controls.Add(Me.tx1)
Me.Controls.Add(Me.lblInfo)
Me.Controls.Add(Me.btnChart)
Me.MaximizeBox = False
Me.MaximumSize = New System.Drawing.Size(624, 432)
Me.MinimumSize = New System.Drawing.Size(624, 432)
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Pie Chart"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnChart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChart.Click
If IsNumeric(tx1.Text) = False Or IsNumeric(tx2.Text) = False Or IsNumeric(tx3.Text) = False Or IsNumeric(tx4.Text) = False Then
MessageBox.Show("Please only choose numbers", "Idiot Alert!")
Exit Sub
End If
Dim Chart As Graphics = Me.lblPie.CreateGraphics
Chart.Clear(Color.FromKnownColor(KnownColor.Control))
Dim pBlack As New Pen(Color.Black, 2)
'store brushes in an array for ease in a loop
Dim intSum As Integer = Int(tx1.Text) + Int(tx2.Text) + Int(tx3.Text) + Int(tx4.Text)
Dim intPercent() As Decimal = {(tx1.Text / intSum), (tx2.Text / intSum), (tx3.Text / intSum), (tx4.Text / intSum)}
lblPercent.Text = ""
Chart.DrawEllipse(pBlack, 0, 0, 300, 300)
Dim intCount As Integer
Dim intNext As Decimal = 0
Randomize()
For intCount = 0 To 3
Dim randBrush As New SolidBrush(Color.FromArgb(CType(Rnd() * 255, Byte), CType(Rnd() * 255, Byte), CType(Rnd() * 255, Byte)))
Chart.FillPie(randBrush, 0, 0, 300, 300, intNext, (intPercent(intCount) * 360))
intNext = intNext + (intPercent(intCount) * 360)
lblPercent.Text = lblPercent.Text & Math.Round(intPercent(intCount) * 100, 2) & "% " & " "
Next
End Sub
End Class