Friday, May 12, 2006

You cannot simply pass the reference to user control.

We have a program which will host multiple map controls, and each map control will have its own legend. It's fine to host muliple maps on different tabs, but it's a little bit tricky to host multiple legends. The end user will only want to see the legend associated with the current active map.

The first approach I tried is to create a form-level legend, and also create each legend inside each map control. And when the map becomes visible, I will do something like this:
frmMain.legend = currentMap.legend.
frmMain.Legend.Refresh().

I thought this will make the frmMain.legend point to the active map legend, and draw the active map legend.

Actually, this is not the case. Simple reference passing won't make the active map legend become the visible legend. And the OnPaint method of the active map won't be called. The paint message will still be sent to original legend.

This issue looks simple, but does take me a while to figure it out.
GISResearch

No comments: