很菜的问题,关于窗体上绘图。。

lzjever 2003-12-09 05:35:13
我以窗体正中设为坐标原点,画出平面直角坐标系
然后以这个点为圆心画圆,怎么样才能在直角坐标系和圆弧组成的扇区里填充颜色?

比如填充半个圆,或着填充1/4个圆的面积等等?
...全文
67 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2003-12-09
  • 打赏
  • 举报
回复
窗体上一个按钮:
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




northwolves 2003-12-09
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim x0 As Long, y0 As Long
x0 = Me.Width / 2
y0 = Me.Height / 2
PSet (x0, y0), vbBlue
Line (x0, y0)-(x0, y0 - 2000)
Line (x0, y0)-(x0 + 2000, y0)
Me.FillStyle = 0
Me.FillColor = vbBlue
Me.Circle (x0, y0), 1000, , 0, 2 * Atn(1)
End Sub
lzjever 2003-12-09
  • 打赏
  • 举报
回复
麻烦能不能具体一点?
如何用line方法来实现?

矩形好办,扇型我不清楚
Kain 2003-12-09
  • 打赏
  • 举报
回复
用vb自己的line方法可以阿

如果高级一点用api啦,这样的帮助往上到处都是,你可以再google上搜索一下

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧