如何直接畫在桌面上

How to draw directly on the Windows desktop, C#?

This question has been asked for other languages, and even for those other languages, I have found their answers lacking in how to exactly do it, cleanly (no messed up screen repaints, etc..).

Is it possible to draw onto the Windows Desktop from C#? I am looking for an example if possible.

Answer 1

Try the following:

using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Runtime.InteropServices;class Program {[DllImport("User32.dll")]static extern IntPtr GetDC(IntPtr hwnd);[DllImport("User32.dll")]static extern int ReleaseDC(IntPtr hwnd, IntPtr dc);static void Main(string[] args) {IntPtr desktop = GetDC(IntPtr.Zero); using (Graphics g = Graphics.FromHdc(desktop)) { g.FillRectangle(Brushes.Red, 0, 0, 100, 100);}ReleaseDC(IntPtr.Zero, desktop);} }

Answer 2

You can try:

Graphics.FromHwnd(IntPtr.Zero)
	

http://stackoverflow.com/questions/1536141/how-to-...

陳鍾誠 (2011年12月20日),(網頁標題) 如何直接畫在桌面上,(網站標題) 免費電子書:C# 程式設計,2011年12月20日,取自 http://cs0.wikidot.com/drawdirectlyonscreen ,網頁修改第 1 版。

arrow
arrow

    Johnson峰 發表在 痞客邦 留言(0) 人氣()