This project has moved and is read-only. For the latest updates, please go here.

what is wrong with this code?

Topics: General Topics
Sep 30, 2006 at 8:12 PM
i am developing a desktop applicatoion. i am not able to view the map,
it showing a blank screen. iam running this application on visual c# 2005

namespace WindowsApplication1
public partial class Form1 : Form
private SharpMap.Map myMap;
public Form1()

private void Form1_Load(object sender, EventArgs e)

myMap = InitializeMap(new System.Drawing.Size(300,400));

//This is the initial view of the map. Zoom to the extents of the map:
myMap.Zoom = myMap.GetExtents().Width;
myMap.Center = myMap.GetExtents().GetCentroid();
//Save the current mapcenter and zoom in the viewstate

//Create the map


private void Form1_Click(object sender, EventArgs e)


private SharpMap.Map InitializeMap(System.Drawing.Size outputsize)

SharpMap.Map map = new SharpMap.Map(outputsize);
SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
layCountries.DataSource = new SharpMap.Data.Providers.ShapeFile(@"C:\Documents and Settings\user\Desktop\demo\App_Data\countries.shp");
layCountries.Style.Fill = new SolidBrush(Color.Green);
//Set the polygons to have a black outline
layCountries.Style.Outline = System.Drawing.Pens.Black;
layCountries.Style.EnableOutline = true;
SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
layRivers.DataSource = new SharpMap.Data.Providers.ShapeFile(@"C:\Documents and Settings\user\Desktop\demo\App_Data\rivers.shp");
layRivers.Style.Line = new Pen(Color.Blue, 1);
return map;


private void CreateMap()
Image img = myMap.GetMap();



thanks & regards
Oct 2, 2006 at 6:35 AM
you forgot to display the Image you got from SharpMap.Map.GetMap(). You should assign the Image to a picture box or some other control for you to see it. Better yet, use a SharpMap.UI.MapImage control.