若仅仅是要获得自己程序中的鼠标位置,建议使用MouseMove事件.
否则使用GetCursorPos这个API,声明如下:
[DllImport("user32.dll", EntryPoint="GetCursorPos")]
public static extern int GetCursorPos (
ref Point lpPoint
);
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace csTest
{
public class Form1 : System.Windows.Forms.Form
{
[DllImport("user32")]
public static extern bool GetCaretPos(ref System.Drawing.Point lpPoint);