How to catch the ending resize window?

后端 未结 5 670
[愿得一人]
[愿得一人] 2020-12-08 05:42

I need catch the event endresize in WPF.

5条回答
  •  情书的邮戳
    2020-12-08 05:53

    NO Timer Needed with very clean solution that have given by @Bohoo up, i just adapted his code from vb.net to c#

         public partial class MainWindow : Window
            {
                public MainWindow()
                {
                    InitializeComponent();
                    this.Loaded += MainWindow_Loaded;
                }
    
                private void MainWindow_Loaded(object sender, RoutedEventArgs e)
                {
                    // this two line have to be exactly onload
                    HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
                    source.AddHook(new HwndSourceHook(WndProc));
                }
    
    
                const int WM_SIZING = 0x214;
                const int WM_EXITSIZEMOVE = 0x232;
                private static bool WindowWasResized = false;
    
    
                private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
                {
                    if (msg == WM_SIZING)
                    {
    
                        if (WindowWasResized == false)
                        {
    
                            //    'indicate the the user is resizing and not moving the window
                            WindowWasResized = true;
                        }
                    }
    
                    if (msg == WM_EXITSIZEMOVE)
                    {
    
                        // 'check that this is the end of resize and not move operation          
                        if (WindowWasResized == true)
                        {
    
                            // your stuff to do 
                            Console.WriteLine("End");
    
                            // 'set it back to false for the next resize/move
                            WindowWasResized = false;
                        }
                    }
    
                    return IntPtr.Zero;
                }
    
        }
    

提交回复
热议问题