コード例 #1
0
 /// <summary>
 /// 根据2个点计算返回Size
 /// </summary>
 /// <param name="StartP"></param>
 /// <param name="EndP"></param>
 /// <returns></returns>
 public static Size PointToSize(Point StartP, Point EndP)
 {
     try
     {
         return(new Size(Math.Abs(StartP.X - EndP.X), Math.Abs(StartP.Y - EndP.Y)));
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
         return(new Size(0, 0));
     }
 }
コード例 #2
0
 /// <summary>
 /// 根据2个点获取一个矩形
 /// </summary>
 /// <param name="left">点1</param>
 /// <param name="right">点2</param>
 /// <returns></returns>
 public static Rect PointToRectangle(Point left, Point right)
 {
     try
     {
         Point RecLeft = new Point(left.X < right.X ? left.X : right.X, left.Y < right.Y ? left.Y : right.Y);
         return(new Rect(RecLeft, PointToSize(left, right)));
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
         return(new Rect());
     }
 }
コード例 #3
0
 /// <summary>
 /// 根据2个矩形获取2个矩形最大的限度的矩形
 /// </summary>
 /// <param name="rct1">矩形1</param>
 /// <param name="rct2">矩形2</param>
 /// <returns>返回一个矩形</returns>
 public static Rect GetOutRectangle(Rect rct1, Rect rct2)
 {
     try
     {
         Rect rct = new Rect();
         rct.X      = rct1.X < rct2.X ? rct1.X : rct2.X;
         rct.Y      = rct1.Y < rct2.Y ? rct1.Y : rct2.Y;
         rct.Width  = rct1.Right > rct2.Right ? rct1.Right - rct.X : rct2.Right - rct.X;
         rct.Height = rct1.Bottom > rct2.Bottom ? rct1.Bottom - rct.Y : rct2.Bottom - rct.Y;
         return(rct);
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
         return(new Rect());
     }
 }