以下仅供参考,本想画一个五角星,不知怎么画不全,只画了一半。
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
'API 函数,这些API函数必须事先声明
'该函数创建多边形
Private Declare Function CreatePolygonRgn Lib "gdi32.dll" (ByRef lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
'该函数创建一个具有指定颜色的逻辑刷子
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
'该函数用指定刷子填充指定区域
Private Declare Function FillRgn Lib "gdi32.dll" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
'该函数删除一个逻辑笔、画笔、字体、位图、区域或者调色板,释放所有与该对象有关的系统资源,在对象被删除之后,指定的句柄也就失效了。
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Const ALTERNATE As Long = 1
Private Const WINDING As Long = 2
Private Sub Command1_Click()
Dim point(10) As POINTAPI
Dim hRgn As Long
Dim hBrush As Long
point(0).x = 120: point(0).y = 5 '设置多边形的顶点坐标,
point(1).x = 140: point(1).y = 70
point(2).x = 210: point(2).y = 70
point(3).x = 150: point(3).y = 100
point(4).x = 180: point(4).y = 175
point(5).x = 120: point(5).y = 120
' point(6).x = 60: point(1).y = 175
' point(7).x = 90: point(2).y = 100
' point(8).x = 30: point(3).y = 70
' point(9).x = 100: point(4).y = 70
hRgn = CreatePolygonRgn(point(0), 6, WINDING)
hBrush = CreateSolidBrush(vbRed) '指定颜色
FillRgn Me.hdc, hRgn, hBrush '填充指定区域
DeleteObject hBrush '释放所有与该对象有关的系统资源
DeleteObject hRgn
End Sub
追问谢谢你!可能我没把问题描述清楚,我想写的程序是这样的,设计一个界面,在程序运行时,在界面上输入几个点的坐标,然后可以根据即时输入的坐标,显示这几个点连成的多边形,不是在代码里就指定要画出怎样的图形来,实在不好意思啊!
追答point(0).x = 120: point(0).y = 5 '设置多边形的顶点坐标,
point(1).x = 140: point(1).y = 70
point(2).x = 210: point(2).y = 70
point(3).x = 150: point(3).y = 100
point(4).x = 180: point(4).y = 175
point(5).x = 120: point(5).y = 120
' point(6).x = 60: point(1).y = 175
' point(7).x = 90: point(2).y = 100
' point(8).x = 30: point(3).y = 70
' point(9).x = 100: point(4).y = 70
把这里修改为根据即时输入的坐标。