我想知道我的光标何时位于特定区域(例如屏幕右侧的小矩形)。
当我的光标位于此区域时,我拖动的表单必须具有更高的高度。
到现在为止,我就是这样:
private void Form1_LocationChanged(object sender, EventArgs e)
{
if (Cursor.Position == new Point(-1037, 516))
{
this.Height = 450;
}
}
因此,我需要创建一个条件来知道我的光标是否位于特定的区域内(屏幕右侧) 谁可以帮我这个事 提前谢谢。
答案 0 :(得分:3)
private void Form1_LocationChanged(object sender, EventArgs e)
{
//THE POSITION OF MY RECTANGLE HERE IS ON THE UPPER LEFT
Rectangle rec = new Rectangle(0,0,100,100); //CHANGE THIS DIMENSION TO YOUR LIKING
if (rec.Contains(Cursor.Position))
{
//DO YOUR STUFF HERE
}
}
希望这有用。
答案 1 :(得分:0)
Cursor.Position
位于屏幕坐标中。您可以测试该位置是否具有指定范围:
Const RANGE_X As Integer = 20;
Const RANGE_Y As Integer = 20;
if ( Screen.PrimaryScreen.Bounds.Width - RANGE_X <= Cursor.Position.X And _
Cursor.Position.Y <= RANGE_Y )
' we're near the top right edge
编辑:测试光标是否在边框区域内,就像@Philip写道:
Const BORDER_SIZE As Integer = 100; ' In pixel
Rectangle border = new Rectangle(
BORDER_SIZE,
BORDER_SIZE,
Screen.PrimaryScreen.Bounds.Width - BORDER_SIZE,
Screen.PrimaryScreen.Bounds.Height - BORDER_SIZE);
If ( Not border.Contains(Cursor.Position) ) Then
' ... yes the cursor is in the border area