本文主要是介绍VB绘制多边形+填充+判断鼠标移入与移出图形的范围(API),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
'创建一个由一系列点围成的区域。windows在需要时自动将最后点与第一点相连以封闭多边形
Private Declare Function CreatePolygonRgn Lib “gdi32” (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 PtInRegion Lib “gdi32” (ByVal hRgn As Long, ByVal X As Long, ByVal Y As Long) As Long
'用指定刷子填充指定区域用指定刷子填充指定区域
Private Declare Function FillRgn Lib “gdi32” (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Const ALTERNATE = 1
Const WINDING = 2
Dim Graph As Long
Dim Ecolor As Long
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = 3
'绘画一个四边形
Dim E(3) As POINTAPI
'第一个点
E(0).X = 12
E(0).Y = 12
'第二个点
E(1).X = 100
E(1).Y = 12
'第三个点
E(2).X = 100
E(2).Y = 36
'第四个点
E(3).X = 12
E(3).Y = 36
Graph = CreatePolygonRgn(E(0), 4, ALTERNATE)
Ecolor = CreateSolidBrush(RGB(255, 0, 0))
Call FillRgn(Me.hdc, Graph, Ecolor)
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If PtInRegion(Graph, X, Y) > 0 Then
Me.Caption = “鼠标在矩形内”
Else
Me.Caption = “鼠标不在矩形内”
End If
End Sub
这篇关于VB绘制多边形+填充+判断鼠标移入与移出图形的范围(API)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!