日期:2014-05-18 浏览次数:21099 次
g.Clear(Color.White);
------解决方案--------------------
桌面么?
那你一定得到桌面的句柄了。
[DllImport("user32.dll", EntryPoint="InvalidateRect")] public static extern int InvalidateRect ( IntPtr hwnd, Rectangle lpRect, bool bErase ); [DllImport("user32.dll", EntryPoint="GetDesktopWindow")] public static extern IntPtr GetDesktopWindow (); //调用 InvalidateRect(GetDesktopWindow(),System.Windows.Forms.Screen.PrimaryScreen.Bounds,true);
------解决方案--------------------
重绘桌面:
C# code
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool RedrawWindow(IntPtr hwnd, RECT rcUpdate, IntPtr hrgnUpdate, int flags);
RedrawWindow(GetDesktopWindow(), null, IntPtr.Zero, 0x85);
------解决方案--------------------
新建控制台程序。粘贴:
[DllImport("user32.dll", EntryPoint = "InvalidateRect")] public static extern int InvalidateRect( IntPtr hwnd, IntPtr lpRect, bool bErase ); [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")] public static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern bool RedrawWindow(IntPtr hwnd, ref Rectangle rcUpdate, IntPtr hrgnUpdate, int flags); static void Main(string[] args) { Thread.Sleep(2000); Console.WriteLine("现在开始绘制屏幕"); Graphics g = Graphics.FromHwnd(IntPtr.Zero); g.DrawLine(Pens.Yellow, new Point(0, 0), new Point(500, 800)); g.Dispose(); Thread.Sleep(2000); Console.WriteLine("现在开始清除屏幕"); Rectangle rect = Screen.PrimaryScreen.Bounds; RedrawWindow(GetDesktopWindow(), ref rect, IntPtr.Zero, 0x85); Console.ReadKey(); }