#region 判断鼠标移动方向
/// <summary>
/// 判断鼠标移动方向
/// </summary>
/// <param name="mousePoint">鼠标坐标</param>
/// <returns></returns>
public MoveType PointInRect(Point mousePoint)
{
Rectangle rectangle = new Rectangle(
startPoint.X,
startPoint.Y,
Math.Abs(endPoint.X - startPoint.X - 2),
Math.Abs(endPoint.Y - startPoint.Y - 2));
if (new Rectangle(
startPoint.X + endPoint.X - startPoint.X - 2,
startPoint.Y + 2,
4,
Math.Abs(endPoint.Y - startPoint.Y - 4)).Contains(mousePoint))
{
return MoveType.ResizeRight;
}
else if (new Rectangle(
startPoint.X,
startPoint.Y + endPoint.Y - startPoint.Y - 2,
Math.Abs(endPoint.X - startPoint.X - 2),
4).Contains(mousePoint))
{
return MoveType.ResizeBottom;
}
else if (new Rectangle(
startPoint.X + endPoint.X - startPoint.X - 2,
startPoint.Y + endPoint.Y - startPoint.Y - 2,
4,
4).Contains(mousePoint))
{
return MoveType.ResizeAll;
}
else if (rectangle.Contains(mousePoint))
{
return MoveType.Move;
}
else
{
return MoveType.None;
}
}
#endregion
/// <summary>
/// 移动类型枚举
/// 方向从‘右’开始,按顺时针方向移动
/// </summary>
public enum MoveType
{
/// <summary>
/// 获得四向大小调整
/// </summary>
Move=0,
/// <summary>
/// 获取左/右双向大小调整
/// </summary>
ResizeRight=1,
/// <summary>
/// 获取上/下双向大小调整
/// </summary>
ResizeBottom=2,
/// <summary>
/// 获取左上/右下双向大小调整
/// </summary>
ResizeAll=3,
/// <summary>
/// 不调整
/// </summary>
None=4
}
c#判断鼠标移动的方向调整矩形大小,布布扣,bubuko.com
c#判断鼠标移动的方向调整矩形大小
原文:http://blog.csdn.net/houxingding/article/details/22662003