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 WindowsFormsHost and override the WndProc method, handling the WM_SIZE
message. This is the message that is sent to a window when the size operation is complete (as opposed to WM_SIZING
, which is sent during the process).
You can also handle the WM_SIZING
message, and not call the base implementation of WndProc when you get this message, to prevent the message from being processed and having the map redraw itself all those times.
The documentation for the WndProc method on the Control class shows how to override WndProc method:
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 value for WM_SIZING and WM_SIZE, 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:
/// <summary>
/// The WM_SIZING message is sent to a window that
/// the user is resizing. By processing this message,
/// an application can monitor the size and position
/// of the drag rectangle and, if needed, change its
/// size or position.
/// </summary>
const int WM_SIZING = 0x0214;
/// <summary>
/// The WM_SIZE message is sent to a window after its
/// size has changed.
/// </summary>
const int WM_SIZE = 0x0005;
And finally, of use will be the documentation for the WM_SIZE and the WM_SIZING window messages:
WM_SIZE
- http://msdn.microsoft.com/en-us/library/ms632646(VS.85).aspx
WM_SIZING
- http://msdn.microsoft.com/en-us/library/ms632647(VS.85).aspx