C#实现显示器中心画点
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("User32.dll")] public extern static System.IntPtr GetDC(System.IntPtr hWnd); private void Form1_Load(object sender, EventArgs e) { System.IntPtr DesktopHandle = GetDC(System.IntPtr.Zero); Graphics g = Graphics.FromHdc(DesktopHandle); Rectangle ScreenArea = System.Windows.Forms.Screen.GetBounds(this); for (; ; ) { g.DrawRectangle(new Pen(Color.Red), new Rectangle(ScreenArea.Width/2, ScreenArea.Height/2, 1, 1)); } } } }