示例#1
0
        private void PictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            if ((Mode == MouseMode.Pan && e.Button == MouseButtons.Left) ||
                (e.Button == MouseButtons.Middle))
            {
                // Start panning the image
                PanStartMousePosition   = e.Location;
                PanStartPicturePosition = PictureBox.PicturePosition;
            }
            else if ((Mode == MouseMode.Pick || Mode == MouseMode.Erase) &&
                     e.Button == MouseButtons.Left &&
                     ActiveAnnotation == null)
            {
                // Pick and activate annotation and possibly also control point

                var result = PictureBox.FindAnnotation(e.Location);

                if (result != null)
                {
                    if (Mode == MouseMode.Pick)
                    {
                        ActiveAnnotation   = result.Item1;
                        ActiveControlPoint = result.Item2;

                        oldControlPointLocations.Clear();
                        oldControlPointLocations.AddRange(ActiveAnnotation.ControlPoints);

                        controlPointSelectLocation = new Vec3(PictureBox.ScreenToPicture(new Vec2(e.Location)), PictureBox.Slice);
                    }
                    else
                    {
                        // Erase annotation
                        PictureBox.Annotations.Remove(result.Item1);
                        Refresh();
                    }
                }
            }
            else if ((Mode == MouseMode.AddAnnotation || Mode == MouseMode.Profile) &&
                     e.Button == MouseButtons.Left &&
                     ActiveAnnotation == null)
            {
                if (Mode == MouseMode.Profile)
                {
                    NewAnnotationName = "Line segment";
                    EraseProfileAnnotation();
                }

                // Add new annotation object
                if (!String.IsNullOrEmpty(NewAnnotationName))
                {
                    ActiveAnnotation = AnnotationFactory.Create(NewAnnotationName);
                    PictureBox.Annotations.Add(ActiveAnnotation);
                    Vec3 pos = new Vec3(PictureBox.ScreenToPicture(new Vec2(e.Location)), PictureBox.Slice);
                    ActiveAnnotation.ControlPoints.Add(pos);
                    ActiveControlPoint = 0;

                    // Add another control point right away if multiple points are required.
                    if (ActiveAnnotation.RequiredPointCount > 1)
                    {
                        ActiveAnnotation.ControlPoints.Add(pos);
                        ActiveControlPoint = 1;
                    }

                    Refresh();

                    if (Mode != MouseMode.Profile)
                    {
                        if (ToolStrip != null)
                        {
                            ToolStrip.ResetAnnotation();
                        }
                    }
                }

                if (Mode == MouseMode.Profile)
                {
                    ProfileAnnotation = ActiveAnnotation;
                    UpdateProfile();
                }
            }
        }