摘要:基于ArcGIS Engine编写的ColorRamp下拉框
首先在form上加载一个imagelist,将要绘制的图片存放到里面(将以自己截个colorramp的图片),再加载combobox,将其Drawmode设置为owenrdrawfixed,然后在其DrawItem事件中编写
Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
Dim iRectangle As System.Drawing.Rectangle
If e.Index = -1 Or sender Is Nothing Then
Exit Sub
Else
绘制背景
e.DrawBackground()
绘制焦点框
e.DrawFocusRectangle()
绘制图例
iRectangle = New System.Drawing.Rectangle(e.Bounds.Left + 1, e.Bounds.Top + 1, 117, 14)
e.Graphics.DrawImage(Me.ImageList1.Images(e.Index), iRectangle)
End If
End Sub
复制代码上面一段代码就可以将imagelist中相应序号的图片绘制到相应序号的item上了,视觉部分完毕,很easy吧?
有了上面的过程我们就应该思考怎么样得到指定colorramp的图像,如果能得到colorramp的图像,只要替换imagelist中的图片就可以实现我们的目的。
注意:下面的代码首先新建一个ESRI.ArcGIS.Display.IGradientFillSymbol和一个ColorRamp
Private Sub DrawColorRamp()
新建 m_FillSymbol和m_ColorRamp
m_FillSymbol.ColorRamp = m_ColorRamp
Me.PictureBox1.Image = SymbolToBitmap(m_FillSymbol, 0, Me.PictureBox1.Width, Me.PictureBox1.Height)
End Sub
复制代码
Friend Function SymbolToBitmap(ByVal iSymbol As ESRI.ArcGIS.Display.ISymbol, ByVal iStyle As Integer, ByVal iWidth As Integer, ByVal iHeight As Integer) As System.Drawing.Bitmap
Dim iHDC As New IntPtr
Dim iBitmap As System.Drawing.Bitmap
Dim iGraphics As System.Drawing.Graphics
Dim itagRECT As ESRI.ArcGIS.Display.tagRECT
Dim iEnvelope As ESRI.ArcGIS.Geometry.IEnvelope
Dim iDisplayTransformation As ESRI.ArcGIS.Display.IDisplayTransformation
Dim iPoint As ESRI.ArcGIS.Geometry.IPoint
Dim iPolyline As ESRI.ArcGIS.Geometry.IGeometryCollection
Dim iPolygon As ESRI.ArcGIS.Geometry.IGeometryCollection
Dim iRing As ESRI.ArcGIS.Geometry.IRing
Dim iSegmentCollection As ESRI.ArcGIS.Geometry.ISegmentCollection
Dim iGeometry As ESRI.ArcGIS.Geometry.IGeometry
iBitmap = New System.Drawing.Bitmap(iWidth, iHeight)
iGraphics = System.Drawing.Graphics.FromImage(iBitmap)
iEnvelope = New ESRI.ArcGIS.Geometry.Envelope
iEnvelope.PutCoords(0, 0, iWidth, iHeight)
With itagRECT
.left = 0
.right = iWidth
.top = 0
.bottom = iHeight
End With
iDisplayTransformation = New ESRI.ArcGIS.Display.DisplayTransformation
With iDisplayTransformation
.VisibleBounds = iEnvelope
.Bounds = iEnvelope
.DeviceFrame = itagRECT
.Resolution = iGraphics.DpiX
End With
iHDC = iGraphics.GetHdc.ToInt32
获取Geometry
If TypeOf (iSymbol) Is ESRI.ArcGIS.Display.IMarkerSymbol Then
Select Case iStyle
Case 0
iPoint = New ESRI.ArcGIS.Geometry.Point
iPoint.PutCoords(iWidth / 2, iHeight / 2)
iGeometry = iPoint
End Select
ElseIf TypeOf (iSymbol) Is ESRI.ArcGIS.Display.ILineSymbol Then
iSegmentCollection = New ESRI.ArcGIS.Geometry.Path
iPolyline = New ESRI.ArcGIS.Geometry.Polyline
Select Case iStyle
Case 0
iSegmentCollection.AddSegment(CreateLine(0, iHeight / 2, iWidth, iHeight / 2))
iPolyline.AddGeometry(iSegmentCollection)
iGeometry = iPolyline
Case 1
iSegmentCollection.AddSegment(CreateLine(0, iHeight / 4, iWidth / 4, 3 * iHeight / 4))
iSegmentCollection.AddSegment(CreateLine(iWidth / 4, 3 * iHeight / 4, 3 * iWidth / 4, iHeight / 4))
iSegmentCollection.AddSegment(CreateLine(3 * iWidth / 4, iHeight / 4, iWidth, 3 * iHeight / 4))
iPolyline.AddGeometry(iSegmentCollection)
iGeometry = iPolyline
End Select
ElseIf TypeOf (iSymbol) Is ESRI.ArcGIS.Display.IFillSymbol Then
iSegmentCollection = New ESRI.ArcGIS.Geometry.Ring
iPolygon = New ESRI.ArcGIS.Geometry.Polygon
Select Case iStyle
Case 0
iSegmentCollection.AddSegment(CreateLine(5, iHeight - 5, iWidth - 6, iHeight - 5))
iSegmentCollection.AddSegment(CreateLine(iWidth - 6, iHeight - 5, iWidth - 6, 6))
iSegmentCollection.AddSegment(CreateLine(iWidth - 6, 6, 5, 6))
iRing = iSegmentCollection
iRing.Close()
iPolygon.AddGeometry(iSegmentCollection)
iGeometry = iPolygon
End Select
ElseIf TypeOf (iSymbol) Is ESRI.ArcGIS.Display.ISimpleTextSymbol Then
Select Case iStyle
Case 0
iPoint = New ESRI.ArcGIS.Geometry.Point
iPoint.PutCoords(iWidth / 2, iHeight / 2)
iGeometry = iPoint
End Select
End If
绘制图形
iSymbol.SetupDC(iHDC, iDisplayTransformation)
iSymbol.Draw(iGeometry)
iSymbol.ResetDC()
iGraphics.ReleaseHdc(iHDC)
iGraphics.Dispose()
SymbolToBitmap = iBitmap
End Function
复制代码过程基本就完成了,应该说没什么难度