ElementHost Layout Problems

后端 未结 2 1078
不思量自难忘°
不思量自难忘° 2020-12-18 13:15

I have a bunch of ElementHosts that I\'m loading onto my form. When this happens, the element hosts all appear with a black background. If I bring another control to front,

相关标签:
2条回答
  • 2020-12-18 13:46

    Holy sh*t, I finally got it working. I tried this code from Google (there were a couple of sources.... How do I suspend painting for a control and its children? ...to name one):

        private const int WM_SETREDRAW = 0x000B;
    
        public static void Suspend(this Control control)
        {
            Message msgSuspendUpdate = Message.Create(control.Handle, WM_SETREDRAW, IntPtr.Zero,
                IntPtr.Zero);
    
            NativeWindow window = NativeWindow.FromHandle(control.Handle);
            window.DefWndProc(ref msgSuspendUpdate);
        }
    
        public static void Resume(this Control control)
        {
            var wparam = new IntPtr(1);
            Message msgResumeUpdate = Message.Create(control.Handle, WM_SETREDRAW, wparam,
                IntPtr.Zero);
    
            NativeWindow window = NativeWindow.FromHandle(control.Handle);
            window.DefWndProc(ref msgResumeUpdate);
    
            control.Invalidate();
        }
    

    It didn't solve my problem and left me with the black messed up backgrounds...BUT I thought to try adding the following to the Resume method:

          public static void Resume(this Control control)
          {
                control.Visible = false;                
                // existing code above....
                control.Visible = true;
          }
    

    and BAM!!! it works.

    0 讨论(0)
  • 2020-12-18 13:47

    Although not being a direct answer to your problem, have you tried to add just one ElementHost (and hence just one WPF UserControl) to your WindowsForm.

    You might achieve this if you create a WPF UserControl which aggregates all your individual WPF UserControl. Is this a viable solution for you? t might reduve Or do you have to mix windows forms controls with wpf ones?

    0 讨论(0)
提交回复
热议问题