public static bool HitTestRectangle(Control owner, int x, int y, Rectangle rect, double angle, bool fill, float lineWidth)
        {
            Form page = owner as Form;

            if (page != null)
            {
                x -= page.AutoScrollPosition.X;
                y -= page.AutoScrollPosition.Y;
            }
            if (angle != 0)
            {
                double xo, yo;
                DrawingItem.Rotate(x, y, rect.Left + rect.Width / 2, rect.Top + rect.Height / 2, angle, out xo, out yo);
                x = (int)xo;
                y = (int)yo;
            }
            if (x >= rect.Left && x <= rect.Right && y >= rect.Top && y <= rect.Bottom)
            {
                if (fill)
                {
                    return(true);
                }
                else
                {
                    if (Math.Abs(x - rect.Left) <= lineWidth)
                    {
                        return(true);
                    }
                    if (Math.Abs(x - rect.Right) <= lineWidth)
                    {
                        return(true);
                    }
                    if (Math.Abs(y - rect.Top) <= lineWidth)
                    {
                        return(true);
                    }
                    if (Math.Abs(y - rect.Bottom) <= lineWidth)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        public override bool HitTest(Control owner, int x, int y)
        {
            Form page = owner as Form;

            if (page == null)
            {
                return(false);
            }
            x -= page.AutoScrollPosition.X;
            y -= page.AutoScrollPosition.Y;
            //
            Graphics g = owner.CreateGraphics();
            SizeF    sf;

            if (string.IsNullOrEmpty(text))
            {
                sf       = g.MeasureString("H", font, new SizeF(g.ClipBounds.Width, g.ClipBounds.Height));
                sf.Width = 1;
            }
            else
            {
                sf = g.MeasureString(text, font, new SizeF(g.ClipBounds.Width, g.ClipBounds.Height));
            }
            _size.Width  = (int)sf.Width;
            _size.Height = (int)sf.Height;
            g.Dispose();
            //
            int w = this.EnableEditing ? (this.TextBoxWidth > _size.Width ? this.TextBoxWidth : _size.Width) : _size.Width;

            //
            if (Angle != 0)
            {
                double xo, yo;
                DrawingItem.Rotate(x, y, pos.X + w / 2, pos.Y + _size.Height / 2, Angle, out xo, out yo);
                x = (int)xo;
                y = (int)yo;
            }
            //
            if (x >= pos.X && x <= pos.X + w && y >= pos.Y && y < pos.Y + _size.Height)
            {
                return(true);
            }
            return(false);
        }
 public static bool HitTestRectangle(Form page, Rectangle rc, double rotateAngle, bool filled, int LineWidth, int x, int y)
 {
     if (page != null)
     {
         x -= page.AutoScrollPosition.X;
         y -= page.AutoScrollPosition.Y;
     }
     if (rotateAngle != 0)
     {
         double xo, yo;
         DrawingItem.Rotate(x, y, rc.X + rc.Width / 2, rc.Y + rc.Height / 2, rotateAngle, out xo, out yo);
         x = (int)xo;
         y = (int)yo;
     }
     if (x >= rc.Left && x <= rc.Right && y >= rc.Top && y <= rc.Bottom)
     {
         if (filled)
         {
             return(true);
         }
         else
         {
             if (Math.Abs(x - rc.Left) <= LineWidth)
             {
                 return(true);
             }
             if (Math.Abs(x - rc.Right) <= LineWidth)
             {
                 return(true);
             }
             if (Math.Abs(y - rc.Top) <= LineWidth)
             {
                 return(true);
             }
             if (Math.Abs(y - rc.Bottom) <= LineWidth)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
 protected override void OnMouseMove(DrawingMark sender, MouseEventArgs e)
 {
     if (sender.Parent == null || pts == null)
     {
         return;
     }
     if (sender.Index == 0)
     {
         //move
         double dx = designer.Marks[0].X - x0 - Page.AutoScrollPosition.X;
         double dy = designer.Marks[0].Y - y0 - Page.AutoScrollPosition.Y;
         for (int i = 0; i < pts.Length; i++)
         {
             pts[i].X += (int)dx;
             pts[i].Y += (int)dy;
             designer.Marks[i + nBaseIndex].X = pts[i].X + Page.AutoScrollPosition.X;
             designer.Marks[i + nBaseIndex].Y = pts[i].Y + Page.AutoScrollPosition.Y;
         }
         designer.Marks[1].X += (int)dx;
         designer.Marks[1].Y += (int)dy;
         x0 = designer.Marks[0].X - Page.AutoScrollPosition.X;
         y0 = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
         calculateBrounds();
     }
     else if (sender.Index == 1)
     {
         //set rotate angle
         double dx = designer.Marks[1].X - designer.Marks[0].X;
         double dy = designer.Marks[1].Y - designer.Marks[0].Y;
         double dd = 0;
         if (Math.Abs(dx) < 0.0001)
         {
             if (dy > 0)
             {
                 dd = 90;
             }
             else
             {
                 dd = 270;
             }
         }
         else
         {
             dd = (Math.Atan(Math.Abs(dy / dx)) / Math.PI) * 180.0;
             if (dx > 0)
             {
                 if (dy < 0)
                 {
                     dd = 360 - dd;
                 }
             }
             else
             {
                 if (dy > 0)
                 {
                     dd = 180 - dd;
                 }
                 else
                 {
                     dd = 180 + dd;
                 }
             }
         }
         if (Angle != dd)
         {
             double angle = dd - Angle;
             nMinX = 20000;
             nMaxX = 0;
             nMinY = 20000;
             nMaxY = 0;
             //
             //angle = (angle/180)*Math.PI;
             double xc = designer.Marks[0].X;
             double yc = designer.Marks[0].Y;
             double xo;
             double yo;
             if (pts != null)
             {
                 for (int i = 0; i < pts.Length; i++)
                 {
                     xo = designer.Marks[i + nBaseIndex].X;
                     yo = designer.Marks[i + nBaseIndex].Y;
                     DrawingItem.Rotate(xo, yo, xc, yc, -angle, out xo, out yo);
                     designer.Marks[i + nBaseIndex].X = (int)Math.Round(xo, 0);
                     designer.Marks[i + nBaseIndex].Y = (int)Math.Round(yo, 0);
                     pts[i].X = (int)Math.Round(xo - Page.AutoScrollPosition.X, 0);
                     pts[i].Y = (int)Math.Round(yo - Page.AutoScrollPosition.Y, 0);
                     if (nMinX > pts[i].X)
                     {
                         nMinX = pts[i].X;
                     }
                     if (nMaxX < pts[i].X)
                     {
                         nMaxX = pts[i].X;
                     }
                     if (nMinY > pts[i].Y)
                     {
                         nMinY = pts[i].Y;
                     }
                     if (nMaxY < pts[i].Y)
                     {
                         nMaxY = pts[i].Y;
                     }
                 }
             }
             Angle = dd;
         }
     }
     else
     {
         //drag corner point
         pts[sender.Index - nBaseIndex].X = designer.Marks[sender.Index].X - Page.AutoScrollPosition.X;
         pts[sender.Index - nBaseIndex].Y = designer.Marks[sender.Index].Y - Page.AutoScrollPosition.Y;
         calculateBrounds();
     }
     if (sender.Index >= nBaseIndex)
     {
         x0 = 0;
         y0 = 0;
         for (int i = 0; i < pts.Length; i++)
         {
             x0 += pts[i].X;
             y0 += pts[i].Y;
         }
         x0 /= pts.Length;
         y0 /= pts.Length;
         designer.Marks[0].X = x0 + Page.AutoScrollPosition.X;
         designer.Marks[0].Y = y0 + Page.AutoScrollPosition.Y;
         calculateBrounds();
     }
     sender.Parent.Invalidate(Bounds);
 }