MapWinGIS:SampleCode-VB Net:ColorSelectedShapes

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

Color Selected Shapes

 '   Example Code Created by Ted Dunsford on April 25, 2008
 '   This example illustrates how to change the fill color of 
 '   selected shapes to cyan.
 Public Class Form1
     Dim layer As Integer
     Dim sf As MapWinGIS.Shapefile
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         AxMap1.SendSelectBoxFinal = True
         AxMap1.SendMouseUp = True
         AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmSelection
     End Sub
     Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
         ' Dimension a new shapefile
         sf = New MapWinGIS.Shapefile
         ' Open the shapfile
         Dim ofd As New OpenFileDialog
         ofd.Filter = "Shapefiles (*.shp) |*.shp"
         If Not ofd.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then Return
         ' Add the shapefile data to the map so that you can see it
         layer = AxMap1.AddLayer(sf, True)
     End Sub
     Private Sub AxMap1_MouseUpEvent(ByVal sender As Object, ByVal e As AxMapWinGIS._DMapEvents_MouseUpEvent) Handles AxMap1.MouseUpEvent
         Dim col As Color = AxMap1.get_ShapeLayerFillColor(layer)
         Dim originalColor As UInt32 = col.B * 256 * 256 + col.G * 256 + col.R
         ' re-color the colored shapes the same color as the layer was colored originally
         AxMap1.set_ShapeLayerFillColor(layer, originalColor)
         AxMap1.set_ShapeLayerLineColor(layer, originalColor)
         AxMap1.set_ShapeLayerPointColor(layer, originalColor)
     End Sub
     Private Sub AxMap1_SelectBoxFinal(ByVal sender As Object, ByVal e As AxMapWinGIS._DMapEvents_SelectBoxFinalEvent) Handles AxMap1.SelectBoxFinal
         Dim ext As New MapWinGIS.Extents
         Dim shapes() As Integer = Nothing
         If sf Is Nothing Then Return
         Dim top, left, bottom, right As Double
         ' Change the extents into geographic coordinates
         AxMap1.PixelToProj(e.left, e.bottom, left, bottom)
         AxMap1.PixelToProj(e.right,, right, top)
         ' Set the region to control
         ext.SetBounds(left, bottom, 0, right, top, 0)
         If (sf.SelectShapes(ext, 0, MapWinGIS.SelectMode.INTERSECTION, shapes) = True) Then
             ' shapes is now an array of integers
             Dim I As Integer
             Dim cyan As UInt32 = 255 * 256 * 256 + 255 * 256
             For I = 0 To shapes.Length - 1
                 ' since the select box is smaller than the map, we already know the shapes selected are in the right place.
                 ' This tests each shape to make sure that they have not had their "visible" property set to false.
                 If AxMap1.get_ShapeVisible(layer, shapes(I)) Then
                     ' Color the shapes cyan
                     AxMap1.set_ShapeFillColor(layer, shapes(I), cyan)
                     AxMap1.set_ShapePointColor(layer, shapes(I), cyan)
                     AxMap1.set_ShapeLineColor(layer, shapes(I), cyan)
                 End If
         End If
     End Sub
 End Class

Posted 4/25/2008 by Ted Dunsford

Retrieved from ""

This page has been accessed 2,343 times. This page was last modified on 25 April 2008, at 22:04.