source: Common/SuspendDrawing.cs

Last change on this file was 13, checked in by chronos, 3 years ago
  • Modified: Fixes to existing classes.
  • Added: File type association method.
  • Added: RecentFiles and Table classes.
File size: 969 bytes
Line 
1using System;
2using System.Runtime.InteropServices;
3using System.Windows.Forms;
4
5namespace Common
6{
7 class SuspendDrawing
8 {
9 [DllImport("user32.dll")]
10 private static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
11 private const int WM_SETREDRAW = 11;
12
13 public static void Suspend(Control parent)
14 {
15 if (parent.Visible) SendMessage(parent.Handle, WM_SETREDRAW, false, 0);
16 }
17
18 public static void Resume(Control parent)
19 {
20 if (parent.Visible) SendMessage(parent.Handle, WM_SETREDRAW, true, 0);
21 parent.Refresh();
22 }
23
24 public static void ExecuteAction(Control parent, Action action)
25 {
26 Suspend(parent);
27 try
28 {
29 action();
30 }
31 finally
32 {
33 Resume(parent);
34 }
35 }
36 }
37}
Note: See TracBrowser for help on using the repository browser.