作业帮 > 综合 > 作业

VB 写一个矩形函数Private Type RECT 'left As Longtop As Longright As

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/14 04:51:29
VB 写一个矩形函数
Private Type RECT '
left As Long
top As Long
right As Long
bottom As Long
End Type
任意框选一个区域,写个RECT函数返回left,top,right,bottom 的值!
Private Function 矩形(Rects() As RECT) As RECT
这里面的函数该怎么写!
End Function
该函数写在模块内!因为划区的时候不一定是在固定窗体,有时候同时画N个区域,都需要这个函数得到数值!有时候是传入若干个矩形组成的数组!
所以该函数主要,要做到的是传入若干个矩形组成的数组!然后返回left,top,right,bottom 的值!
这个简单.你把四边分别处理就行了,统计出每个边的极值,最后组合成一个四边形.
再问: 请给出正确代码谢谢,因为我写不来! 但却需要这个函数!
再答: '获取一个可以覆盖所有矩形的大矩形 Private Function 矩形(Rects() As RECT) As RECT Dim I As Integer, R As RECT If Rects Is Nothing Then Exit Function R.left = Rects(LBound(Rects)).left R.top = Rects(LBound(Rects)).top R.right = Rects(LBound(Rects)).right R.bottom = Rects(LBound(Rects)).bottom For I = LBound(Rects) + 1 To UBound(Rects) If R.left < Rects(I).left Then R.left = Rects(I).left If R.top < Rects(I).top Then R.top = Rects(I).top If R.right > Rects(I).right Then R.right = Rects(I).right If R.bottom > Rects(I).bottom Then R.bottom = Rects(I).bottom Next 矩形 = R End Function