Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable updating a form in Windows Forms?

Tags:

.net

winforms

During a complicated update I might prefer to display all the changes at once. I know there is a method that allows me to do this, but what is it?

like image 341
Tomas Pajonk Avatar asked Sep 24 '08 12:09

Tomas Pajonk


2 Answers

I think this.SuspendLayout() & ResumeLayout() should do it

like image 165
gil Avatar answered Sep 17 '22 16:09

gil


I don't find SuspendLayout() and ResumeLayout() do what you are asking for. LockWindowsUpdate() mentioned by moobaa does the trick. However, LockWindowUpdate only works for one window at a time.

You can also try this:

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

public partial class Form1 : Form
{
    [DllImport("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
    private const int WM_SETREDRAW = 11; 

    public Form1()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      SendMessage(this.Handle, WM_SETREDRAW, false, 0);

      // Do your thingies here
      SendMessage(this.Handle, WM_SETREDRAW, true, 0);

      this.Refresh();
    }
}
like image 34
Magnus Johansson Avatar answered Sep 19 '22 16:09

Magnus Johansson