ElementHost Layout Problems

后端 未结 2 1087
不思量自难忘°
不思量自难忘° 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.

提交回复
热议问题