'/*************************design by 撒卡*************************/ '/功能:使用GDI花饼图demo '/时间:07.09.30 '/****************************************************************/
Private Const Pi As Single = 3.1415926
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With PicShow '.Top = 10 '.Left = 10 '.Width = 300 '.Height = 300 .Dock = DockStyle.Fill End With Me.Controls.Add(PicShow) End Sub
Private Sub Mypaint(ByVal e As PaintEventArgs)
Dim MyCircle As Graphics = e.Graphics Dim Myline As Graphics = e.Graphics Dim MyPen As New Pen(Color.Black) Dim myRect As New Rectangle(50, 50, 200, 200) 'MyCircle.DrawEllipse(MyPen, myRect) '边框,被覆盖 Myline.DrawLine(MyPen, 50, 150, 150, 150)
'划分区间 Dim sRectPer(2) As Single, x1(2) As Single, y1(2) As Single '定义的数组数为区间数-1 sRectPer(0) = Radian("30", "30", "30", "40") x1(0) = 150 - Math.Cos(sRectPer(0)) * 100 '半径为100 y1(0) = 150 - Math.Sin(sRectPer(0)) * 100 Myline.DrawLine(MyPen, x1(0), y1(0), 150, 150)
'填充区间 Dim x2(3) As Single, y2(3) As Single '数组大小等于区间数 For i As Double = 0 To sRectPer(0) Step 0.0001 x2(0) = 150 - Math.Cos(i) * 100 y2(0) = 150 - Math.Sin(i) * 100 Myline.DrawLine(Pens.Magenta, x2(0), y2(0), 150, 150) Next
For j As Double = sRectPer(0) To sRectPer(1) Step 0.0001 x2(1) = 150 - Math.Cos(j) * 100 y2(1) = 150 - Math.Sin(j) * 100 Myline.DrawLine(Pens.SeaGreen, x2(1), y2(1), 150, 150) Next Dim newline As Graphics = e.Graphics For k As Double = sRectPer(1) To Pi * 2 Step 0.0001 x2(2) = 150 - Math.Cos(k) * 100 y2(2) = 150 - Math.Sin(k) * 100 newline.DrawLine(Pens.Orange, x2(2), y2(2), 150, 150) Next 'Dim a As Single = percentage("30", "30", "30", "40") 'Debug.Print(a.ToString)
Private Sub PicShow_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PicShow.Paint Mypaint(e) End Sub
Private Function percentage(ByVal rect As Integer, ByVal ParamArray rectall() As Integer) As Single Dim sum As Int64 For i As Integer = 0 To UBound(rectall, 1) sum += rectall(i) Next percentage = rect / sum End Function
Private Function Radian(ByVal rect As Integer, ByVal ParamArray rectall() As Integer) As Double radian = percentage(rect, rectall) * Pi * 2 End Function End Class