Windows Forms test (newbie)

Topics: General Topics
Sep 6, 2006 at 9:35 AM
Hi, i'm newbie of SharpMap.
I want try it with a C# Windows Form and shape file.
I try this code:

map = new SharpMap.Map(mapImage1.Size)
layer = new SharpMap.Layers.VectorLayer("Italy");
layer.DataSource = new SharpMap.Data.Providers.ShapeFile(@"it.shp", true);
mapImage1.Map = map;
where mapImage is a Control Object on Windows Form.
I can't see anything.
Anyone can help me? Thank's a lot.
Sep 12, 2006 at 2:22 PM
Just as new, but got it working In my experience a piece of sample code helps most of the times. I hope that works for you to. So, below a piece of code coming from my latest trial (desktop) application. The actual map is in the right hand panel of a splitContainer here.

private void initMap()
Size sz = new Size((int)((float)splitContainer1.Panel2.Size.Width * 0.98), (int)((float)splitContainer1.Panel2.Size.Height * 0.98));
Map = new SharpMap.Map(sz);
MapImage = new SharpMap.Forms.MapImage();

MapImage.Size = new System.Drawing.Size(sz.Width, sz.Height); //Set output size

Map.MinimumZoom = 1;
Map.BackColor = Color.White;

MapImage.ActiveTool = SharpMap.Forms.MapImage.Tools.None;
MapImage.Map = Map;


private void AddLayer(SharpMap.Layers.VectorLayer layer)
if (layer != null)
SharpMap.Geometries.BoundingBox mapExtents = MapImage.Map.Envelope;

if (Map.Layers.Count == 1)

System.Drawing.Image imgMap = Map.GetMap();
MapImage.Image = imgMap;

String Text = layer.LayerName;
if (Text.IndexOf("\\",0) > 0) { Text = Text.Substring(Text.LastIndexOf("\\") + 1); }

Good luck.
Jul 13, 2007 at 5:57 AM

i am fresher in sharpmap , can u tell me how to add the sharpmap in vb.net2.0 (windows form) and how to add the shape files in sharpmap control plz help me.

Aug 1, 2007 at 11:44 AM
You'll also find some useful instruction in the DemoWinForm Project in the most recent release: 0.9 Production.
Aug 8, 2011 at 10:31 AM
Edited Aug 8, 2011 at 11:36 AM