Demo for Desktop

Sep 2, 2006 at 1:13 PM
Hi,

I need a demo form Windows Forms, but not found, only ASP.Net. Exists?
Developer
Sep 2, 2006 at 3:21 PM
Ehm did you check the newest release?!?
The code doesn't differ that much between ASP.NET and Windows (only the UI stuff)
Nov 12, 2006 at 5:25 PM
having the same problem and thinking that samples are the best
here is my first try
find the data for maps and replace with your own
this just remove sand ads the city layer uppon bouble click
enjoy

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SharpMap;
using SharpMap.Forms;


namespace WindowsApplication1
{
public partial class Form1 : Form
{
private SharpMap.Map myMap;
static bool t = false;
public Form1()
{
InitializeComponent();
Form1_Load(this, null);
}

private void Form1_Load(object sender, EventArgs e)
{
myMap = InitializeMap(new System.Drawing.Size(3000, 4000));

//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();
myMap.ZoomToExtents();

//Save the current mapcenter and zoom in the viewstate
Form1_RedrawMap();
}

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\ts\My Documents\ofer\sharpmap\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\ts\My Documents\ofer\sharpmap\demo\App_Data\rivers.shp");
layRivers.Style.Line = new Pen(Color.Blue, 1);
SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
layCities.DataSource = new SharpMap.Data.Providers.ShapeFile(@"C:\Documents and Settings\ts\My Documents\ofer\sharpmap\demo\App_Data\cities.shp");
layCities.Style.Line = new Pen(Color.LightGreen, 1);
map.Layers.Add(layCountries);
map.Layers.Add(layRivers);
map.Layers.Add(layCities);
return map;


}


private Image CreateMap()
{
Image img = myMap.GetMap();
return img;
}

private void Form1_RedrawMap()
{
//Create the map
Image img = CreateMap();
// show map
navair1.Map = myMap;
}

private void Form1_SizeChanged(object sender, EventArgs e)
{
Form1_RedrawMap();
}

private void navair1_MouseDoubleClick(object sender, MouseEventArgs e)
{
t = !t;
SharpMap.Map m;
m = this.navair1.Map;
SharpMap.Layers.ILayer c = m.GetLayerByName("Cities");
c.Enabled =t;
Form1_RedrawMap();
}

}
}
Dec 18, 2006 at 3:16 PM
Yep, an example is always great. But your code cannot be compiled.
What does "navair1" variable mean?