Hi, As shapes that are programmatically added can be moved by the user with the mouse, I wonder if it is possible to ice the shapes so that the user cannot move it ?
Do you know if that is possible and how ? (without having to copy/paste the map on a picturebox :) )
Wilfried
01-11-2005, 06:00 AM
Hi,
Yes it sure is possible. On this forum you find an article how to make pushpins inmoveable. Same trick could be used for shapes I suppose. http://www.mp2kmag.com/a97--pushpins.immoveable.mappoint.html Check also what has been discussed here: http://www.mp2kmag.com/mappoint/discussion/viewtopic.asp?t=4315
Thanks. I've taken a look at these threads and they are interesting.
In order to prevent the user from moving pushpins and shapes I've tried the following code but I alway get a "Stack Overflow" error from the C# runtime :
private void axMappointControl1_SelectionChange(object sender, AxMapPoint._IMappointCtrlEvents_SelectionChangeEve nt e)
{
// I don't cast anything here because I consider any selection to be a shape or pushpin
MapPoint.Shape sp;
MapPoint.Location loc;
try
{
loc = axMappointControl1.ActiveMap.GetLocation(80,0,0);
sp = axMappointControl1.ActiveMap.Shapes.AddShape(MapPo int.GeoAutoShapeType.geoShapeRectangle,loc,1,1);
sp.Select();
sp.Delete();
}
catch(Exception)
{
}
}
the error is :
An unhandled exception of type 'System.StackOverflowException' occurred in axinterop.mappoint.dll
Wilfried
01-11-2005, 08:36 AM
Hi,
sp.Select();
This is the quilty one :) When Select is called the while function will be re-entered, again and again until the stack flows over :(
You have to set a busy flag on entering the function an first check if it is true, if true then exit. When the function exit you set the flag again to false.
Do not put the flag on the stack.
something like this will do:
if (!select_change_busy) {
select_change_busy = true;
// here the code
select_change_busy = false;
}
In the article it was with the mousebutton I think. But it is similar.
Great !!!! Thank you mister Wilfried !!!
Let's share this wonderful tip :) :
bool select_change_busy = false;
private void axMappointControl1_SelectionChange(object sender, AxMapPoint._IMappointCtrlEvents_SelectionChangeEve nt e)
{
if (!select_change_busy)
{
select_change_busy=true;
MapPoint.Shape sp;
MapPoint.Location loc;
try
{
loc = axMappointControl1.ActiveMap.GetLocation(80,0,0);
sp = axMappointControl1.ActiveMap.Shapes.AddShape(MapPo int.GeoAutoShapeType.geoShapeRectangle,loc,1,1);
sp.Select();
sp.Delete();
}
catch(Exception)
{
}
select_change_busy=false;
}
}
Wilfried
01-11-2005, 12:27 PM
Hi Jaba,
Thanks for the feedback. Doing so other can benefit from it also :)
Tip: You can put code between tags, then it is nice formatted and ident :)
Hi Wilfried...
You're welcome :)
Now I want to deactivate the moving of shapes only, because with the source code above this also deactivates the viewing of pushpins' labels :(
I've tried the following to deactivate the moving of shapes only but I can't understand why it does not work as I would like it to ?
bool select_change_busy = false;
private void axMappointControl1_SelectionChange(object sender, AxMapPoint._IMappointCtrlEvents_SelectionChangeEve nt e)
{
if (!select_change_busy)
{
select_change_busy=true;
MapPoint.Shape sp;
MapPoint.Location loc;
MapPoint.Shape sp2;
try
{
sp2 = (MapPoint.Shape) e.pNewSelection;
loc = axMappointControl1.ActiveMap.GetLocation(80,0,0);
sp = axMappointControl1.ActiveMap.Shapes.AddShape(MapPo int.GeoAutoShapeType.geoShapeRectangle,loc,1,1);
sp.Select();
sp.Delete();
sp2=null;
}
catch(Exception)
{
}
select_change_busy=false;
}
}