IRubberBand Interface
IRUbberBand是一个能帮助我们画图形元素的接口(如点,线,面等)。它有实现绘制几何形体(Geometry)的方法TrackNew,以及移动一个一个几何形体的方法TrackExisting:
| Description | |
|---|---|
| TrackExisting | Indicates if to move or reshape an existing shape on the specified screen in response to a mouse down event. |
| TrackNew | Call in response to mouse down event to rubberband a new shape on the specified screen. |
有若干组件类实现了这个接口
| CoClasses and Classes | Description |
|---|---|
| RubberCircle | Rubberbanding class for circles. |
| RubberEnvelope | Rubberbanding class for simple envelopes. |
| RubberLine | Rubberbanding class for lines. |
| RubberPoint | Rubberbanding class for points. |
| RubberPolygon | Rubberbanding class for polygons. |
| RubberRectangularPolygon | Rubberbanding class for rectangular polygons (rotatable envelopes). |
下面的例子介绍了如何利用RubberPolygon 组件类和IRubberBand接口创建一个允许用户创建或移动多边形的工具。
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
Dim pMXDoc As IMxDocument
Dim pPoly As IPolygon
Dim pGraCont As IGraphicsContainer
Dim pGraContSel As IGraphicsContainerSelect
Dim pRubberPoly As IRubberBand
Dim pElem As IElement
' QI for the MXDocument interface
Set pMXDoc = ThisDocument
' QI for the IGraphicsContainerSelect interface on the document's activeview
Set pGraCont = pMXDoc.ActiveView
' Create a new RubberPolygon
Set pRubberPoly = New RubberPolygon
'Check which mouse button was pressed
If button = 1 Then ' If button 1 (left) then create a new polygon (TrackNew)
' Return a new Polygon from the tracker object using TrackNew
Set pPoly = pRubberPoly.TrackNew(pMXDoc.ActiveView.ScreenDisplay, Nothing)
If Not pPoly Is Nothing Then
' Create a new PolygonElement and set its Geometry
Set pElem = New PolygonElement
pElem.Geometry = pPoly
'Add the new element at Z order zero
pGraCont.AddElement pElem, 0
End If
Else ' If button 2 (right) then move an existing polygon (TrackExisting)
' QI for IGraphicsContainerSelect
Set pGraContSel = pGraCont
' Check that we have some selected elements
If pGraContSel.ElementSelectionCount > 0 Then
' If there is only one selected element then get it
If pGraContSel.ElementSelectionCount = 1 Then
Set pElem = pGraContSel.SelectedElement(0)
' If there is more than one selected element then get the dominant one
ElseIf pGraContSel.ElementSelectionCount > 1 Then
Set pElem = pGraContSel.DominantElement
End If
' Check that the selected element is a PolygonElement
If TypeOf pElem Is IPolygonElement Then
' Create a new RubberPolygon
Set pRubberPoly = New RubberPolygon
' Retrieve the current geometry of our element
Set pPoly = pElem.Geometry
' Use track existing, passing in the Polygon's geometry by reference
' NB all User input is now handled by the RubberBand until the Mouse up occurs)
pRubberPoly.TrackExisting pMXDoc.ActiveView.ScreenDisplay, Nothing, pPoly
' Set the Element's geometry (pPoly has been altered by TrackExisting)
pElem.Geometry = pPoly
' Update the element
pGraCont.UpdateElement pElem
End If
End If
End If
' Refresh the activeview
pMXDoc.ActiveView.Refresh
End Sub-----------------------------------------------------------
佛对我说:你心里有尘。我用力的拭擦。

浙公网安备 33010602011771号