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));
            }

        }
    }
}

 

posted @ 2017-09-05 09:56  XinYiBuFang  阅读(831)  评论(0编辑  收藏  举报