窗体上一个按钮:
Option Explicit
Private Declare Function Pie Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal x3 As Long, ByVal y3 As Long, ByVal x4 As Long, ByVal y4 As Long) As Long
Private Const transPI = 1.74532925199433E-02
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Enum PenStyle
lineSolid = 0
lineDash = 1
lineDot = 2
lineDashDot = 3
lineDashDotDot = 4
lineInvisible = 5
lineInsideSolid = 6
End Enum
Private Sub Command1_Click()
Dim i As Long
For i = 0 To 360 Step 30
DrawPie Me, Me.ScaleWidth / 2, Me.ScaleHeight / 2, 100, i - 30, i, i * 30000, vbBlue, 1, lineSolid
Next
'下面的是你需要的
' For i = 0 To 360 Step 90
' DrawPie Me, Me.ScaleWidth / 2, Me.ScaleHeight / 2, 100, i - 90, i, i * 300, vbBlue, 1, lineSolid
' Next
End Sub
'自定义子过程DrawPie,功能:绘制扇形
'参数mObj:欲绘制扇形的对象,可为Form、PictureBox等
'参数circleCenterPointX,circleCenterPointY:扇形对应圆心的横、纵坐标
'参数Radius:扇形对应圆的半径
'参数BeginAngle:扇形对应起始角的角度值
'参数EndAngle:扇形对应结束角的角度值
'参数FillColor:扇形的填充颜色
'参数LineColor:扇形外框线的颜色
'参数LineWidth:扇形外框线的宽度,单位为Pixel
'参数nPenStyle:扇形外框线的样式,可为实线、破折线、点线等
Private Sub DrawPie(mObj As Object, circleCenterPointX As Long, circleCenterPointY As Long, Radius As Long, ByVal BeginAngle As Double, ByVal EndAngle As Double, ByVal FillColor As Long, ByVal LineColor As Long, ByVal LineWidth As Long, ByVal nPenStyle As PenStyle)
mObj.AutoRedraw = False
mObj.ScaleMode = vbPixels
Dim x1 As Long, y1 As Long
Dim x2 As Long, y2 As Long
Dim x3 As Long, y3 As Long
Dim x4 As Long, y4 As Long
Dim BeginRadian As Double, EndRadian As Double
x1 = circleCenterPointX - Radius
y1 = circleCenterPointY - Radius
x2 = circleCenterPointX + Radius
y2 = circleCenterPointY + Radius
BeginRadian = BeginAngle * transPI
EndRadian = EndAngle * transPI
x3 = circleCenterPointX + CLng(10000 * Math.Cos(EndRadian))
y3 = circleCenterPointY + CLng(10000 * Math.Sin(EndRadian))
x4 = circleCenterPointX + CLng(10000 * Math.Cos(BeginRadian))
y4 = circleCenterPointY + CLng(10000 * Math.Sin(BeginRadian))
Dim hBrush As Long, hOldBrush As Long, hPen As Long, hOldPen As Long
hBrush = CreateSolidBrush(ByVal FillColor)
hOldBrush = SelectObject(mObj.hdc, hBrush)
hPen = CreatePen(nPenStyle, LineWidth, LineColor)
hOldPen = SelectObject(mObj.hdc, hPen)
Pie mObj.hdc, x1, y1, x2, y2, x3, y3, x4, y4
SelectObject mObj.hdc, hOldBrush
SelectObject mObj.hdc, hOldPen
DeleteObject hBrush
End Sub