如何直接在Windows桌面上,C#在画画吗? [英] How to draw directly on the Windows desktop, C#?
本文介绍了如何直接在Windows桌面上,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..).
是否有可能从C#绘制到Windows桌面?我找了一个例子,如果可能的。
Is it possible to draw onto the Windows Desktop from C#? I am looking for an example if possible.
推荐答案
请尝试以下操作:
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);
}
}
这篇关于如何直接在Windows桌面上,C#在画画吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文