如何判断鼠标在某个视口区域内?[已解决!]
本帖最后由 作者 于 2008-11-14 15:59:02 编辑如何判断鼠标在某个视口区域内?这样我就可以得到该视口的比例,相应的就可以在图纸空间中创建正确的尺寸标注了,谢谢大家! <p>Public Function getVportCustomScale(ByVal Point As Variant) As Double '得到当前鼠标点击点的视口比例,如果点内没有视口返回1<br/>Dim n As Long '视口个数<br/>Dim minxx() As Double<br/>Dim maxxx() As Double<br/>Dim minyy() As Double<br/>Dim maxyy() As Double<br/>Dim sc() As Double '视口的比例<br/>Dim mid As Variant<br/>Dim h, w As Double '暂存视口的宽度和高度<br/>Dim newVport As AcadPViewport<br/>Dim i As Long<br/>Dim NewEnt(0 To 0) As AcadEntity<br/>Dim ss As AcadSelectionSet<br/>Set ss = ThisDrawing.SelectionSets.Add("ss")<br/>For i = 0 To ThisDrawing.PaperSpace.Count - 1<br/> Set NewEnt(0) = ThisDrawing.PaperSpace.Item(i)<br/> If NewEnt(0).ObjectName = "AcDbViewport" Then<br/> ss.AddItems NewEnt<br/> End If<br/>Next i<br/>n = ss.Count<br/>ReDim minxx(0 To n) As Double<br/>ReDim maxxx(0 To n) As Double<br/>ReDim minyy(0 To n) As Double<br/>ReDim maxyy(0 To n) As Double<br/>ReDim sc(0 To n) As Double<br/>For i = 1 To n - 1<br/> Set newVport = ss.Item(i)<br/> mid = newVport.center<br/> w = newVport.Width<br/> h = newVport.Height<br/> minxx(i) = mid(0) - 0.5 * w<br/> minyy(i) = mid(1) - 0.5 * h<br/> maxxx(i) = mid(0) + 0.5 * w<br/> maxyy(i) = mid(1) + 0.5 * h<br/> sc(i) = 1 / newVport.CustomScale<br/>Next i<br/>For i = 1 To n - 1<br/> If Point(0) > minxx(i) And Point(0) < maxxx(i) And Point(1) > minyy(i) And Point(1) < maxyy(i) Then<br/> getVportCustomScale = sc(i)'这里第i个就是鼠标所在的视口<br/> ss.Delete<br/> Exit Function<br/> End If<br/>Next i<br/>getVportCustomScale = 1</p><p>ss.Delete<br/>End Function</p> 顶起来,正需要这个问题的
页:
[1]