Connection Legend with Map

Feb 17, 2013 at 10:01 PM

I'm beginner in using MapWinGis. I use SharpDevelop and my program is in C#.

how to connect legend with map that means if I uncheck layer in legend this layer disappear in map and if I check, layer appear. And if I move up layer in legend, layer in map go up.

Feb 18, 2013 at 12:22 PM
You should have a look at the source code of MapWindow:

From memory I think the legend control has a property you can use to put the axmap object name is.

Feb 19, 2013 at 7:26 PM
Thank for your response.
I tried this but it doesn't work. If I set property map I have error:

"Cannot implicitly convert type 'AxMapWinGIS.AxMap' to 'MapWinGIS.Map' (CS0029) - C:\C#\testSHP\testSHP\MainForm.Designer.cs:60,23"
The type 'MapWinGIS.Map' is defined in an assembly that is not referenced. You must add a reference to assembly 'Interop.MapWinGIS"

If I set property:

this.legend1.Map = (MapWinGIS.Map)axMap1;

I have error : Unable to cast object of type 'AxMapWinGIS.AxMap' to type 'MapWinGIS.Map'.

I have referrence :

Below is source code:
private void InitializeComponent()
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
        this.axMap1 = new AxMapWinGIS.AxMap();
        this.legend1 = new LegendControl.Legend();
        // axMap1
        this.axMap1.Enabled = true;
        this.axMap1.Location = new System.Drawing.Point(240, 29);
        this.axMap1.Name = "axMap1";
        this.axMap1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMap1.OcxState")));
        this.axMap1.Size = new System.Drawing.Size(502, 297);
        this.axMap1.TabIndex = 0;
        // legend1
        this.legend1.BackColor = System.Drawing.Color.White;
        this.legend1.Location = new System.Drawing.Point(12, 29);
        this.legend1.Map = (MapWinGIS.Map)axMap1;
        this.legend1.Name = "legend1";
        this.legend1.SelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
        this.legend1.SelectedLayer = -1;
        this.legend1.Size = new System.Drawing.Size(222, 297);
        this.legend1.TabIndex = 1;
It is strange, and what is difference AxMapWinGIS.AxMap and MapWinGIS.Map?

Feb 21, 2013 at 8:49 AM
You are using the interop dlls that belong to the ocx?
It is best to download all 3 from
Those interop dlls are generated by Visual Studio when you add the ocx to your form. I don't know the difference.