1,点相对于屏幕的位置
[DllImport("user32.dll")]//当前引用必须在GetCursorPos方法声明上面
private static extern bool GetCursorPos(out Point p);
使用
Point p;
GetCursorPos(out p);
2,点相对于控件的位置
MouseEventArgs。location
3,划定区域
/// <summary>
/// checkBox按钮的位置范围
/// </summary>
GraphicsPath gpCheckBoxPos = new GraphicsPath();
public Region myRegion = new Region();
Point[] pt = new Point[]{
new Point(0,0),
new Point(28,0),
new Point(28,28),
new Point(0,28)
};
gpCheckBoxPos.Reset();//清除
gpCheckBoxPos.AddLines(pt);//四个点划线,收尾相连
myRegion.MakeEmpty();
myRegion.Union(gpCheckBoxPos);
4,判断当前点是否点击在当前区域
if (myRegion.IsVisible(e.Location))
{
}