Exemple #1
0
 /// <summary>
 /// 使控件的指定区域无效(将其添加到控件的更新区域,下次绘制操作时将重新绘制更新区域),并向控件发送绘制消息。还可以使分配给该控件的子控件无效。
 /// </summary>
 /// <param name="hWnd">控件句柄。</param>
 /// <param name="region">要使之无效的 System.Drawing.Region。</param>
 /// <param name="invalidateChildren">若要使控件的子控件无效,则为 true;否则为 false。</param>
 public static void Invalidate(IntPtr hWnd, Region region, bool invalidateChildren)
 {
     if (region == null)
     {
         Invalidate(hWnd, invalidateChildren);
     }
     else if (GetIsHandleCreated(hWnd))
     {
         IntPtr hRgn = GetHRgn(hWnd, region);
         try
         {
             if (invalidateChildren)
             {
                 UnsafeNativeMethods.RedrawWindow(hWnd, IntPtr.Zero, hRgn, NativeMethods.RDW_ALLCHILDREN | NativeMethods.RDW_INVALIDATE);//.Net Framework :多NativeMethods.RDW_ERASE
             }
             else
             {
                 UnsafeNativeMethods.InvalidateRgn(hWnd, hRgn, false);//.Net Framework :支持透明为true,否则false
             }
         }
         finally
         {
             UnsafeNativeMethods.DeleteObject(hRgn);
         }
     }
 }