• VB.NET中用GDI+画饼图


    Public Class Form1
        Private Const Pi As Single = 3.1415926

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDrawing.Click
            'Debug.Print("tttt")

        End Sub

        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)

            sRectPer(1) = Radian("60", "30", "30", "40") 'srectPer(n)的radian函数的第一个参数为前n+1个参数的和
            x1(1) = 150 - Math.Cos(sRectPer(1)) * 100
            y1(1) = 150 - Math.Sin(sRectPer(1)) * 100
            Myline.DrawLine(MyPen, x1(1), y1(1), 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)

            '标示区间
            With lblrectA
                .Top = (150 + y1(0)) * 0.5
                .Left = (50 + x1(0)) * 0.3
                .Text = "组分A比例:" & percentage("30", "30", "30", "40")
                .BackColor = Color.Magenta
                .ForeColor = Color.White
            End With
            With lblrectB
                .Top = (y1(0) + y1(1)) * 0.5
                .Left = (x1(0) + x1(1)) * 0.4
                .Text = "组分B比例:" & percentage("30", "30", "30", "40")
                .BackColor = Color.SeaGreen
                .ForeColor = Color.White
            End With
            With lblrectC
                .Top = (150 + y1(1)) * 0.5
                .Left = (50 + x1(1)) * 0.3
                .Text = "组分C比例:" & percentage("40", "30", "30", "40")
                .BackColor = Color.Orange
                .ForeColor = Color.White
            End With

            MyPen.Dispose()
        End Sub


        Private Sub PicShow_Paint(ByVal sender As System.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

  • 相关阅读:
    棋盘完美覆盖数(小规模原理实现)
    Codeforces 115A Party (并查集思维)
    datetime日期和时间
    range与enumerate的区别
    爬取爱套图网上的图片
    python爬取365好书中小说
    列表和元组的方法
    字符串中的方法
    从电源问题出发,带你揭秘新体系结构范式 COA
    KubeCon 2020 演讲集锦|《阿里巴巴云原生技术与实践 13 讲》开放下载
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2010365.html
Copyright © 2020-2023  润新知