コード例 #1
0
        private void measureButton_Click(object sender, EventArgs e)
        {
            using (MeasureForm form = new MeasureForm()) {
                if (form.ShowDialog() == DialogResult.OK)
                {
                    switch (form.status)
                    {
                    case MeasureStatus.MeasureSelected:
                        //выбрано значение
                        measureMode = MeasureStatus.MeasureSelected;
                        MeasureController.SelectMeasure(form.SelectedMeasure);
                        filterInfoGrid.Rows.Add("Масштаб", form.SelectedMeasure.Scale);
                        MouseMode = MouseMode.Arrow;
                        MenuButtonsOn();
                        break;

                    case MeasureStatus.MeasureRequested:
                        //запрос на создание замеров
                        measureMode = MeasureStatus.MeasureRequested;
                        MouseMode   = MouseMode.Measure;
                        MenuButtonsOff();
                        break;
                    }
                }
            }
        }
コード例 #2
0
        private void mainPictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            MouseState   = e;
            MousePressed = true;

            switch (MouseMode)
            {
            case MouseMode.Measure:
                if (measureMode == MeasureStatus.MeasureRequested)
                {
                    Point convertedPoint = CoordinatesController.PBtoPCoordinates(
                        e.Location,
                        PictureBoxSize,
                        PictureSize);

                    if (MeasurePoints.Count == 0)
                    {
                        //добавляем первую точку
                        MeasurePoints.Add(convertedPoint);
                    }
                    else if (MeasurePoints.Count == 1)
                    {
                        //добавляем вторую точку
                        MeasurePoints.Add(convertedPoint);
                        //вызываем форму масштабов
                        double distance = MeasurePoints[0].DistanceTo(MeasurePoints[1]);
                        using (MeasureForm form = new MeasureForm(mainPictureBox.Image.Size, distance)) {
                            if (form.ShowDialog() == DialogResult.OK)
                            {
                                measureMode = MeasureStatus.MeasureSelected;
                                MeasureController.SelectMeasure(form.SelectedMeasure);
                                filterInfoGrid.Rows.Add("Масштаб", form.SelectedMeasure.Scale);
                            }

                            MouseMode = MouseMode.Arrow;
                            MenuButtonsOn();
                        }
                        MeasurePoints.Clear();
                    }
                }
                break;

            case MouseMode.Ruler:
                if (RulerPoints.Count == 2)
                {
                    RulerPoints.Clear();
                }

                RulerPoints.Add(e.Location);
                mainPictureBox.Invalidate();
                mainPictureBox.Update();
                break;
            }
        }