Change Arx1Map from another form

Good weekend,

I am trying to change map from another form. Say AxMap1 is on Form1, I want to change the color of map or select by attributes by open another form (form2), build my query and pass it to Query, all fine.

Then access Form1 from form2:
Form1 fm = new Form1();

object selected returns the correct number, but fm.axMap1.ZoomToSelected(layerHandle); doesn’t work?

Same thing to change color: (color code selection is on another form). I can see it is working but doesn’t show on map.

So my question is: how do you work with map controls from another form?

if (sf.Table.Query(query, ref result, ref error))
{
int[] shapes = result as int[];
if (shapes != null)
{
for (int i = 0; i < shapes.Length; i++)
{
sf.set_ShapeSelected(shapes[i], true);
}
}
fm.axMap1.ZoomToSelected(layerHandle);

            fm.axMap1.Refresh();
           // fm.axMap1.Redraw();
            MessageBox.Show("Objects selected: " + sf.NumSelected);
        }
        else
        {
            MessageBox.Show("No shapes agree with the condition.");
        }

Hello @lang, sorry for the delayed response.

To an extent, your question is more of a .NET Forms question than it is a MapWinGIS question. Without seeing more code, it’s hard to say what’s happening.

  1. Do you know that the variable layerHandle is the correct handle for your layer?
  2. It’s not clear that the Shapefile (sf) is the same layer that is associated with layerHandle.
  3. Perhaps if you put all of the code into one form, and see if it works there? In one form, you could iron out any MapWinGIS issues in the code, then split it out and debug any multiple Form issues.

Hope that helps. If you can post more complete code, I may not have time to try running it, but I, or perhaps others, could at least look it over.

Regards,
Jerry.

Jerry, thank you for the kind response.
In one form, it works well. And I checked the attributes value one passing the shapefile from one form to another, it is the right one. Need to refresh on the second form to see the change.