在本示例中,我们通过 GDI+ 实现了一个简单的 饼图绘制。代码具体如下:

Imports System.Drawing
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '定义一块区域
        Dim image As New Bitmap(350, 200)
        Dim g As Graphics = Graphics.FromImage(image)
        g.Clear(Color.White)
        Dim outline As New Rectangle(10, 5, 300, 100)
        '绘制饼图
        g.DrawEllipse(New Pen(Color.Black, 8.0F), outline)
        g.FillPie(New SolidBrush(Color.Red), outline, -20.0F, 120.0F)
        g.FillPie(New SolidBrush(Color.Yellow), outline, 100.0F, 120.0F)
        g.FillPie(New SolidBrush(Color.Blue), outline, 220.0F, 100.0F)
        g.FillPie(New SolidBrush(Color.Green), outline, 320.0F, 40.0F)
        '显示并保存图片
        Me.BackgroundImage = image
        Me.BackgroundImageLayout = ImageLayout.Center
        image.Save(\"mypie.jpg\")
    End Sub
End Class

在这段代码中,使用 Graphics.DrawEllipseGraphics.FillPie 方法生成了饼图的轮廓和各部分填充颜色,最终保存为 mypie.jpg 文件。