How to find out when WindowsFormsHost resizes in WPF?

I have a window map in WindowsFormsHost and I need to resize it using a window.

I'm just not sure which event to listen to do this. I need the map to change only after the mouse is up, otherwise it will fail and try to sketch itself a million times when you resize the window very slowly.

+5
source share
2 answers

Waiting for a timer is a very, very bad idea, quite simple, it is a heuristic, and you guess when the resize operation is performed.

WindowsFormsHost WndProc, WM_SIZE. , ( WM_SIZING, ).

WM_SIZING WndProc , .

WndProc Control , WndProc:

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.wndproc(VS.71).aspx

, , .

, WM_SIZING WM_SIZE, :

http://www.pinvoke.net/default.aspx/Enums/WindowsMessages.html

, , :

/// <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;
+7

:

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/8453ab09-ce0e-4e14-b30b-3244b51c13c4

, , SizeChanged, . , "Tick" , , - . , , . wpf, wpf-.

public MyUserControl()
{
    _resizeTimer.Tick += _resizeTimer_Tick;
}

DispatcherTimer _resizeTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 1500), IsEnabled = false };

private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
    _resizeTimer.IsEnabled = true;
    _resizeTimer.Stop();
    _resizeTimer.Start();
}

int tickCount = 0;
void _resizeTimer_Tick(object sender, EventArgs e)
{
    _resizeTimer.IsEnabled = false;
    //you can get rid of this, it just helps you see that this event isn't getting fired all the time
    Console.WriteLine("TICK" + tickCount++);

    //Do important one-time resizing work here
    //...
}
-3

All Articles