I’ve got a windows forms map in a WindowsFormsHost, and I need it to resize with the window.
I’m just not sure what event to listen to, to do this. I need the map to only resize once the mouse is up, otherwise it lags out, and tries drawing itself a million times when you resize a window really slowly.
Waiting on a timer is a very, very bad idea, quite simply, it’s a heuristic and you are guessing when the resize operation is done.
A better idea would be to derive a class from
WindowsFormsHostand override theWndProcmethod, handling theWM_SIZEmessage. This is the message that is sent to a window when the size operation is complete (as opposed toWM_SIZING, which is sent during the process).You can also handle the
WM_SIZINGmessage, and not call the base implementation ofWndProcwhen you get this message, to prevent the message from being processed and having the map redraw itself all those times.The documentation for the
WndProcmethod on theControlclass shows how to overrideWndProcmethod:http://msdn.microsoft.com/en-us/library/system.windows.forms.control.wndproc(VS.71).aspx
Even though it is for a different class, it’s the same exact principal.
Additionally, you will need the values for the
WM_SIZINGandWM_SIZEconstants, which you can find here:http://www.pinvoke.net/default.aspx/Enums/WindowsMessages.html
Note that you don’t need everything from the link above, just the declarations for those two values: