This project is read-only.

Problem with MouseMoveEvent, Scale in C# application

Jan 18, 2013 at 1:26 PM


I'm beginner in using MapWinGis. I use SharpDevelop and my program is in C#. I try to load raster (img, geotiff, etc) and show current coordinates in labels, current scale, measure distances, Iąve read a lot of forums, documentation in VB and I can't get rid of problems.

This is a for my test application:

 So what is wrong with current cordinates mouse cursor? (I think if I solve this problem I will be able to write method for measure) how can I show current projection? It possible to reproject raster? And last question do I need write a event for legend that I uncheck raster in legend, this raster disappear from map?

Please help with my problems. I wasted a lot of time so I decided to write this post.

Best regards Slawek

using System;
using System.Data;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;
using System.Globalization;
using MapWindow;

namespace testMapWinGIS
    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm : Form
        string geoFile;
        int layerHandle;
        public MainForm()
            // The InitializeComponent() call is required for Windows Forms designer support.
            legend1.Map = (MapWinGIS.Map)axMap1.GetOcx();
            // TODO: Add constructor code after the InitializeComponent() call.
        void Button2Click(object sender, EventArgs e)
        void Button1Click(object sender, EventArgs e)
            axMap1.CursorMode = MapWinGIS.tkCursorMode.cmNone;
            //axMap1.MapCursor = MapWinGIS.tkCursor.crsrCross;
            MapWinGIS.GeoProjectionClass projection = new MapWinGIS.GeoProjectionClass();
            try {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Wspierane formaty |*.img;*.tif;*.sid;*.jp2;*.bmp;*.jpg;*.gif;*.png|" + 
                    "Erdas Imagine (*.img)|*.img|" +
                "GeoTif (*.tif)|*.tif|" + "MrSID Images (*.sid)|*.sid|" + 
                "JPEG2000 Images (*.jp2)|*.jp2|" + "Bitmap Images (*.bmp)|*.bmp|" + 
                "JPEG Images (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "GIF Images (*.gif)|*.gif|" + 
                "PNG Images (*.png)|*.png|" + "All files (*.*)|*.*";
                if (open.ShowDialog() == DialogResult.OK)
                    geoFile = open.FileName;
                } else {
                    MessageBox.Show("Nie załadowano danych");
                MapWinGIS.Image newImage = new MapWinGIS.Image();
                if (newImage.Open(geoFile, MapWinGIS.ImageType.USE_FILE_EXTENSION, falsenull))
                    //newImage.SetProjection("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
                    axMap1.AddLayer(newImage, true);
                    //StatusBarProjection.Text = newImage.
                    layerHandle = legend1.Layers.Add(newImage, true);
                    legend1.Map.set_LayerName(layerHandle, System.IO.Path.GetFileName(geoFile));
                    label1.Text = "1 : " + Math.Round(axMap1.CurrentScale).ToString();
                    label2.Text = newImage.GetProjection().ToString();
            } catch (Exception) {
                MessageBox.Show("Wystąpił błąd z ładowaniem danych");
        void AxMap1MouseMoveEvent(object sender, AxMapWinGIS._DMapEvents_MouseMoveEvent e)
            double x = 0.0, y = 0.0;
            axMap1.PixelToProj((double)e.x, (double)e.y, ref x, ref y);

            string format = "#.000";
            string sx = (x < -180.000) ? "<180.0" : (x > 180.0) ? ">180.0" : x.ToString(format);
            string sy = (y < -90.0) ? "<90.0" : (y > 90.0) ? ">90.0" : y.ToString(format);
            label3.Text = string.Format("X={0}; Y={1}", sx, sy);
            //double x = 0;
            //double y = 0;

Jan 18, 2013 at 2:44 PM

One point of help: On the form loading event you should set the Map property which sends the mouse move and mouse down events. Otherwise you will not receive those events.

Jan 18, 2013 at 6:54 PM

I've done it. 

this.axMap1.MouseMoveEvent += new AxMapWinGIS._DMapEvents_MouseMoveEventHandler(this.AxMap1MouseMoveEvent);

But it doesn't work.

Jan 18, 2013 at 8:37 PM

I was actually looking for this line of code:

axMap1.SendMouseDown = true;

	AxMap1.SendMouseMove = True

for example see:,6332

Jan 19, 2013 at 9:37 AM

That was it. I haven't seen SendMouseMove. I am very grateful for Your help.

I would like to ask You for three more things:

- show current scale of map

- how to reproject images in map?

- 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.

Can You help me with this last problems? Thank You very much if You can and if You can't :)


Feb 4, 2013 at 4:09 PM
Can you ask only one question at a time?

Please create new posts for your remaining questions and we will try to answer them.