c#判断鼠标移动的方向调整矩形大小
/// <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
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。