GetCursorPos

 



获取桌面坐标



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region
     
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool GetCursorPos(out POINT pt);
        [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int X;
            public int Y;
            public POINT(int x, int y)
            {
                this.X = x;
                this.Y = y;
            }
        }
        #endregion

        private void timer1_Tick(object sender, EventArgs e)
        {
            POINT pt = new POINT();
            GetCursorPos(out pt);
            textBox1.Text = string.Format("{0},{1}", pt.X,pt.Y);
        }
    }
}





附件列表

     

    posted @ 2016-11-23 17:32  XE2011  阅读(477)  评论(0编辑  收藏  举报