■ Control 클래스에서 컨트롤 페인팅을 보류하고 재개하는 방법을 보여준다.
▶ ControlHelper.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
namespace TestProject; /// <summary> /// 컨트롤 헬퍼 /// </summary> public class ControlHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// WM_SETREDRAW /// </summary> private const int WM_SETREDRAW = 0x000b; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 페인팅 보류하기 - SuspendPainting(control) /// <summary> /// 페인팅 보류하기 /// </summary> /// <param name="control">컨트롤</param> public static void SuspendPainting(Control control) { Message message = Message.Create(control.Handle, WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero); NativeWindow nativeWindow = NativeWindow.FromHandle(control.Handle); nativeWindow.DefWndProc(ref message); } #endregion #region 페인팅 재개하기 - ResumePainting(control) /// <summary> /// 페인팅 재개하기 /// </summary> /// <param name="control">컨트롤</param> public static void ResumePainting(Control control) { IntPtr wordParameter = new IntPtr(1); Message message = Message.Create(control.Handle, WM_SETREDRAW, wordParameter, IntPtr.Zero); NativeWindow nativeWindow = NativeWindow.FromHandle(control.Handle); nativeWindow.DefWndProc(ref message); control.Invalidate(); } #endregion } |