Disable refresh screen until end of operation

4

Currently I have a code that refreshes me MdiCildren screens, the fact is that by doing this visually it is a bit ugly until it ends, so I need to know if it is possible and how to do not paint anything on the screen until you arrive a point and that the screen is refrected at that time

mixing code and pseudocodigo would be something like that

        noRefrescar();
        foreach( Form f in this.MdiChildren)
        {
            f.WindowState = FormWindowState.Maximized;
        }
        Refrescar();

Thank you.

    
asked by U. Busto 23.02.2017 в 09:24
source

2 answers

5

In the documentation of C # you can see the methods SuspendLayout and ResumeLayout that do just what you need:

this.SuspendLayout();
foreach( Form f in this.MdiChildren)
{
    f.WindowState = FormWindowState.Maximized;
}
this.ResumeLayout(true);

There are other ways, using Workers in other threads that send you a ready when what you need to detect has ended but for your specific case it is not necessary so much complication.

    
answered by 23.02.2017 / 11:50
source
1

You could use the SuspendLayout and ResumeLayout methods, but if they do not work, you could implement these two methods:

 [DllImport("user32.dll")]
 public static extern int SendMessage(IntPtr wnd, int msg, bool param, int lparam);

 public static int WM_SETREDRAW = 0x000B;

 //Suspende el Redibujo del control
 public static void SuspendDrawing(IntPtr handle)
 {
    SendMessage(handle,WM_SETREDRAW, false, 0);
 }

 //Habilita el redibujo del control
 public static void ResumeDrawing(IntPtr handle)
 {
     SendMessage(handle, WM_SETREDRAW, true, 0);
 }

You can implement it as follows:

SuspendDrawing(this.Handle);
foreach( Form f in this.MdiChildren)
{
     f.WindowState = FormWindowState.Maximized;
}
ResumeDrawing(this.Handle);
this.Refresh();
this.Update();

NOTE: For no reason should you forget to call the ResumeDrawing method, so you could avoid any drawing problem of the object.

    
answered by 23.02.2017 в 22:58