code_junkie

How do I disable updating a form in WinForms?

Nov 11th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. [DllImport("user32.dll")]
  2. private static extern long LockWindowUpdate(long Handle);
  3.  
  4. try {
  5. // Lock Window...
  6. LockWindowUpdate( frm.Handle );
  7. // Perform your painting / updates...
  8.  
  9. } finally {
  10. // Release the lock...
  11. LockWindowUpdate( 0 );
  12. }
  13.  
  14. using System;
  15. using System.Collections.Generic;
  16. using System.ComponentModel;
  17. using System.Data;
  18. using System.Drawing;
  19. using System.Text;
  20. using System.Windows.Forms;
  21. using Microsoft.Win32;
  22. using System.Runtime.InteropServices;
  23.  
  24. namespace WindowsTest
  25. {
  26. public partial class Form1 : Form
  27. {
  28. [DllImport("user32.dll")]
  29. public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
  30. private const int WM_SETREDRAW = 11;
  31.  
  32. public Form1()
  33. {
  34. InitializeComponent();
  35. }
  36.  
  37. private void button1_Click(object sender, EventArgs e)
  38. {
  39. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  40.  
  41. // Do your thingies here
  42.  
  43. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  44.  
  45. this.Refresh();
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment