Example #1
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (this.xtraTabControl1.SelectedTabPageIndex != 0)
                {
                    return;
                }

                if (e.Button == MouseButtons.None && regionArrayCollection.Count > 0)
                {
                    Point btn = new Point(e.X, e.Y);
                    if (regionCollection[0].IsVisible(btn))
                    {
                        Cursor = Cursors.SizeAll;
                    }
                    else
                    {
                        Cursor = Cursors.Default;
                    }
                    if (picked)
                    {
                        for (int k = 0; k < regionArrayCollection[0].Length; k++)
                        {
                            if (regionArrayCollection[0][k].IsVisible(btn))
                            {
                                if (k < 2)
                                {
                                    Cursor = Cursors.SizeNWSE;
                                }
                                else
                                {
                                    Cursor = Cursors.SizeNESW;
                                }
                            }
                            //else
                            //    Cursor = Cursors.Default;
                        }
                    }
                }

                if (e.Button != MouseButtons.Left)
                {
                    return;
                }

                int width  = ControlService.SignCombo.Current.Width;
                int height = ControlService.SignCombo.Current.Height;
                if (rdbOriginalPictureRatio.Checked)
                {
                    height = CurrentImage.Height;
                    width  = CurrentImage.Width;
                }
                newPoint.EndX = e.X;
                newPoint.EndY = e.Y;
                if (rdbOverallSignRatio.Checked &&
                    changed == true &&
                    drawImageType[regionIndex] != (int)ImageType.Path
                    )
                {
                    if (pointIndex == 2)
                    {
                        int x = pointArray[regionIndex][3].X + (width * (pointArray[regionIndex][3].Y - e.Y)) / height;
                        newPoint.EndX = x;
                    }
                    if (pointIndex == 3)
                    {
                        int y = pointArray[regionIndex][2].Y + (height * (pointArray[regionIndex][2].X - e.X)) / width;
                        newPoint.EndY = y;
                    }
                    //newPoint.EndY = e.Y;
                    //tempChangePoint.StartP = new Point(tempChangePoint.StartP.X, tempChangePoint.EndX - ((width * (tempChangePoint.EndY - e.Y)) / height));
                    //tempChangePoint.EndY = tempChangePoint.StartP.Y + ((height * (e.X - tempChangePoint.StartP.X)) / width);
                }
                //this.statusBar.Panels[1].Text = "Point:" + e.X.ToString() + "," + e.Y.ToString();
                switch (newType)
                {
                case ImageType.Pick:
                    if (picked == true && changed != true)
                    {
                        mouseMove = true;
                        int MoveX = newPoint.EndP.X - newPoint.StartP.X;
                        int MoveY = newPoint.EndP.Y - newPoint.StartP.Y;
                        RegionMove(regionIndex, MoveX, MoveY);
                        if (drawImageType[regionIndex] != (int)ImageType.Path)
                        {
                            drawingList[regionIndex].pointchange(pointArray[regionIndex]);
                        }
                        else
                        {
                            regionPath = (GraphicsPath)mousePath.Clone();
                            Matrix translateMatrix = new Matrix();
                            translateMatrix.Translate(MoveX, MoveY);
                            regionPath.Transform(translateMatrix);
                            drawingList[regionIndex].pathChange(regionPath, false);
                        }
                        PointChange(regionIndex);
                    }
                    if (changed == true && drawImageType[regionIndex] != (int)ImageType.Path)
                    {
                        mouseMove = true;

                        //if (pointIndex < 2)
                        pointArray[regionIndex][pointIndex] = newPoint.EndP;
                        //else
                        //{
                        //    if(pointIndex =2)
                        //        pointArray[regionIndex][0] =new Point(newPoint.EndP.
                        //}
                        if (pointIndex < 2)
                        {
                            tempChangePoint      = new MousePoint(pointArray[regionIndex][1 - pointIndex].X, pointArray[regionIndex][1 - pointIndex].Y);
                            tempChangePoint.EndX = pointArray[regionIndex][pointIndex].X;
                            if (rdbOverallSignRatio.Checked || rdbOriginalPictureRatio.Checked)
                            {
                                //tempChangePoint.StartP.X+e.X-tempChangePoint.StartP.X
                                tempChangePoint.EndY = tempChangePoint.StartP.Y + ((height * (e.X - tempChangePoint.StartP.X)) / width);     // pointArray[regionIndex][pointIndex].Y;
                            }
                            else
                            {
                                tempChangePoint.EndY = pointArray[regionIndex][pointIndex].Y;
                            }
                            regionCollection[regionIndex] = new Region(tempChangePoint.Rect);
                            if (pointIndex == 0)
                            {
                                pointArray[0][0] = tempChangePoint.Rect.Location;
                                pointArray[0][1] = new Point(tempChangePoint.StartP.X + tempChangePoint.Rect.Width, tempChangePoint.EndP.Y);

                                pointArray[0][2] = new Point(tempChangePoint.EndX, tempChangePoint.EndP.Y);
                                pointArray[0][3] = new Point(tempChangePoint.StartP.X + tempChangePoint.Rect.Width, tempChangePoint.Rect.Location.Y);
                            }
                            else
                            {
                                pointArray[0][0] = tempChangePoint.Rect.Location;
                                pointArray[0][1] = new Point(tempChangePoint.EndX, tempChangePoint.EndY);
                                pointArray[0][2] = new Point(tempChangePoint.StartP.X + tempChangePoint.Rect.Width, tempChangePoint.StartP.Y);
                                pointArray[0][3] = new Point(tempChangePoint.StartP.X, tempChangePoint.EndY);
                            }
                        }
                        if (pointIndex == 3)
                        {
                            tempChangePoint      = new MousePoint(pointArray[regionIndex][3].X, pointArray[regionIndex][3].Y);
                            tempChangePoint.EndX = pointArray[regionIndex][2].X;
                            //if (rdbOverallSignRatio.Checked)
                            //{
                            //    tempChangePoint.StartP =new Point(tempChangePoint.StartP.X, tempChangePoint.EndY + ((height * (tempChangePoint.EndX - e.X)) / width));
                            //    //tempChangePoint.EndY = tempChangePoint.StartP.Y + ((height * (tempChangePoint.StartP.X-e.X)) / width);
                            //}
                            //else
                            tempChangePoint.EndY          = pointArray[regionIndex][2].Y;
                            regionCollection[regionIndex] = new Region(tempChangePoint.Rect);
                            pointArray[0][0] = tempChangePoint.Rect.Location;
                            pointArray[0][1] = new Point(tempChangePoint.StartP.X + tempChangePoint.Rect.Width, tempChangePoint.EndP.Y);

                            pointArray[0][2] = new Point(tempChangePoint.EndX, tempChangePoint.EndY);
                            pointArray[0][3] = newPoint.EndP;    // new Point(tempChangePoint.StartP.X, tempChangePoint.StartP.Y);// newPoint.EndP;
                            if (rdbOverallSignRatio.Checked || rdbOriginalPictureRatio.Checked)
                            {
                                pointArray[0][3] = new Point(tempChangePoint.StartP.X, tempChangePoint.EndY + ((height * (tempChangePoint.EndX - e.X)) / width));    // newPoint.EndP;
                            }
                        }
                        if (pointIndex == 2)
                        {
                            tempChangePoint      = new MousePoint(pointArray[regionIndex][2].X, pointArray[regionIndex][2].Y);
                            tempChangePoint.EndX = pointArray[regionIndex][3].X;
                            tempChangePoint.EndY = pointArray[regionIndex][3].Y;



                            regionCollection[regionIndex] = new Region(tempChangePoint.Rect);

                            pointArray[0][0] = tempChangePoint.Rect.Location;
                            pointArray[0][1] = new Point(tempChangePoint.StartP.X + tempChangePoint.Rect.Width, tempChangePoint.EndP.Y);

                            pointArray[0][2] = new Point(tempChangePoint.StartP.X + tempChangePoint.Rect.Width, tempChangePoint.StartP.Y);
                            pointArray[0][3] = new Point(tempChangePoint.EndX, tempChangePoint.EndY);
                        }



                        drawingList[regionIndex].pointchange(pointArray[regionIndex]);
                        PointChange(regionIndex);
                    }
                    break;
                }
                pictureBox1.Invalidate();
                SetStatus();
            }
            catch
            { }
        }
Example #2
0
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button != MouseButtons.Left)
                {
                    return;
                }

                if (this.xtraTabControl1.SelectedTabPageIndex != 0)
                {
                    return;
                }

                newPoint = new MousePoint(e.X, e.Y);
                switch (newType)
                {
                case ImageType.Pick:
                    if (picked == true)
                    {
                        for (int k = 0; k < regionArrayCollection[regionIndex].Length; k++)
                        {
                            if (regionArrayCollection[regionIndex][k].IsVisible(newPoint.StartP))
                            {
                                pointIndex = k;
                                changed    = true;
                                break;
                            }
                            else
                            {
                                changed = false;
                            }
                        }
                        if (changed == true)
                        {
                            break;
                        }
                    }
                    int m = regionIndex;
                    if (picked == true)
                    {
                        m = (regionIndex + 1) % regionCollection.Count;                 //循环下一项开始
                    }
                    int n = 0;
                    for (; n < regionCollection.Count; n++)
                    {
                        if (m >= regionCollection.Count)
                        {
                            m = 0;
                        }
                        if (regionCollection[m++].IsVisible(newPoint.StartP))
                        {
                            pointViewList = new DShapeList();
                            regionIndex   = m - 1;
                            tempMovePoint = new Point[pointArray[regionIndex].Length];
                            for (int j = 0; j < pointArray[regionIndex].Length; j++)
                            {
                                tempMovePoint[j] = pointArray[regionIndex][j];
                            }
                            PointView(regionIndex);
                            this.pictureBox1.Invalidate();
                            picked = true;
                            if (drawImageType[regionIndex] == (int)ImageType.Path)
                            {
                                mousePath = drawingList[regionIndex].pathChange(mousePath, true);
                            }
                            changed = false;
                            break;
                        }
                        else
                        {
                            //pointViewList = new DShapeList();
                            //this.pictureBox1.Invalidate();
                            picked = false;
                        }
                    }
                    break;
                }
            }
            catch
            { }
        }