Forum guidelines
SuspendLayout C# Forms
Posted By Administrator on 20 Feb 2003
I have written a Flowsheeting GUI, where the user can add, delete reposition UserControls on the screen at runtime and connect them with GDI+ Drawn Lines to represent connections. The only problem is that I can not figure out how to prevent the form redrawing each UserControl one at a time when the form is Zoomed in or out, is there any way to have reposition the usercontrols and resize them before they are redrawn to the screen. I have tried using the suspend and resume layout methods withut any success on the both the parent form and on each user control. In VBA and so on there was a function called ScrenUpdating=false which achieved what I wanted, but in C# I can not find an equivalent command.
Re: SuspendLayout C# Forms
Posted By Administrator on 06 Mar 2003  
I noticed this.SuspendLayout(); and this.ResumeLayout(false); generated by VS.NET automatically for me, maybe you could have a look into these methods.
Re: SuspendLayout C# Forms
Posted By Administrator on 07 Mar 2003  
Thanks for the reply, but if you look at the title of the original post or the text, I allready tried these methods and they had no beneficial effect.
Re: SuspendLayout C# Forms
Posted By John JC on 05 Aug 2007  
try control.BeginUpdate() and control.EndUpdate()
Re: SuspendLayout C# Forms
Posted By Alan C Balkany on 12 Sep 2007  

(I just posted this to another thread, but it appears to be an answer to your question, so I'm reposting it here.  Hope it helps...)


You can try SuspendLayout () before initializing your form and ResumeLayout () after initialization.  Sometimes this doesn't work.  When it doesn't, you can try using the Win32 functions:

Outside of your method:

using Microsoft.Win32;
using System.Runtime.InteropServices;

        public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
        private const int WM_SETREDRAW = 11;


Before drawing:

            SendMessage(ObjectControlPanel.Handle, WM_SETREDRAW, false, 0);

After drawing:

            SendMessage(ObjectControlPanel.Handle, WM_SETREDRAW, true, 0);

You may then need to call Refresh ().

Re: SuspendLayout C# Forms
Posted By Michael Arrington on 27 Mar 2009  
Thanks for the tip.  That is VERY useful!!!  It's now part of my library and it works very well.

C# Corner Annual Conference 2016


Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.