Пример #1
0
        private void pictureBoxMain_MouseDown(object sender, MouseEventArgs e)
        {
            //обрабатываем сообщения только от контейнера с изображением
            //PictureBox pic = (PictureBox)sender;
            //if (pic != pictureBox) return;
            CalcRatio();
            PointF p = new PointF(e.X, e.Y);
            PointF q = CvtCoord_WindowToImage(p, new PointF(0, 0), ratio, image.Size, pictureBox.Size);

            //labelPointP.Text = p.X + "; " + p.Y;
            //labelPointQ.Text = q.X + "; " + q.Y;

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                /*CalcRatio();
                 *
                 * //PointF center = new PointF(pictureBox.Width/2, pictureBox.Height/2);
                 * PointF center = new PointF(0, 0);
                 * PointF src = new PointF(e.X, e.Y);
                 * PointF dst = CvtCoord_WindowToImage(src, center, ratio, image.Size, pictureBox.Size);
                 *
                 * //Points.Add(new Point(e.X, e.Y));
                 * Points.Add(new Point((int)dst.X, (int)dst.Y));
                 * pictureBox.Refresh();*/

                if (mouseMode == MouseMode.RectAdd)
                {
                    Rectangle    coords = new Rectangle((int)q.X, (int)q.Y, 1, 1);
                    UltimateRect ulr    = new UltimateRect(/*Rects.Count,*/ coords);
                    figures.Add(ulr);

                    //сразу же запускаем редактирование этого прямоугольника
                    mouseMode           = MouseMode.RectEditResize;
                    IndexOfCapturedRect = figures.Count - 1;
                    CapturedNode        = RectEditMode.RightBottom;

                    pictureBox.Refresh();
                }
                if (mouseMode == MouseMode.None)
                {
                    if (CheckRectCapture(p, q) == false)
                    {
                        mouseMode           = MouseMode.None;
                        IndexOfCapturedRect = -1;
                    }
                }
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                //Points.Clear();

                /*Rects.Clear();
                 * mouseMode = MouseMode.None;
                 * IndexOfCapturedRect = -1;
                 * pictureBox.Refresh();*/
            }
        }
Пример #2
0
        public UltimateRect ParseString(string line)
        {
            char[]   separators = { ' ' };
            string[] splitted   = line.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            if (splitted.Length < 5)
            {
                return(null);
            }
            int       ID     = Convert.ToInt32(splitted[0]);
            int       x      = Convert.ToInt32(splitted[1]);
            int       y      = Convert.ToInt32(splitted[2]);
            int       width  = Convert.ToInt32(splitted[3]);
            int       height = Convert.ToInt32(splitted[4]);
            Rectangle R      = new Rectangle(x, y, width, height);

            UltimateRect URect = new UltimateRect(R);

            return(URect);
        }