Exemple #1
0
 //作者信息
 private void AboutButton_Click(object sender, EventArgs e)
 {
     MessageBoxes.Author();
 }
Exemple #2
0
        //预览或编辑
        private void PreviewOrEdit(object sender, MouseEventArgs e)
        {
            try
            {
                //预览
                if (IsDrawing && IsPreviewing)
                {
                    PlotPoint Preview = new PlotPoint
                    {
                        X = e.X,
                        Y = e.Y
                    };
                    ClearAndDraw();
                    if (Line.Points.Count > 0)
                    {
                        if (PolyLineCalcGroupBox.Visible)
                        {
                            PolyLineLengthLabel.Text = "折线长度:" + (((Algorithm.GetPolyLineLength(Line.Points) + Algorithm.GetSingleLineLength(Line.Points[Line.Points.Count - 1], Preview)) / (PlotPointPictureBox.Width)) * Convert.ToDouble(RatioTextBox.Text)).ToString("0.0000") + " (m)";
                        }
                        if (IsPolygonCheckBox.Checked)
                        {
                            if (Line.Points.Count > 1)
                            {
                                PolyLineDrawing.DrawPolygon(Line.Points, PlotPointPictureBox, PolygonColorPictureBox.BackColor, PolygonTransparencyTrackBar.Value * 255 / (PolygonTransparencyTrackBar.Maximum - PolygonTransparencyTrackBar.Minimum), Preview);
                                List <PlotPoint> PreviewArea = new List <PlotPoint>();
                                for (int i = 0; i < Line.Points.Count(); i++)
                                {
                                    PreviewArea.Add(Line.Points[i]);
                                }
                                PreviewArea.Add(Preview);
                                PolygonAreaLabel.Text = "多边形面积:" + (Algorithm.GetPolygonArea(PreviewArea, PlotPointPictureBox, Convert.ToSingle(RatioTextBox.Text))).ToString("0.0000") + "(m ^ 2)";
                            }
                            PolyLineDrawing.DrawPreviewLine(Line.Points[0], Preview, PlotPointPictureBox, Algorithm.InverseColor(LineColorPictureBox.BackColor), LineWidthTrackBar.Value);
                        }
                        PolyLineDrawing.DrawPreviewLine(Line.Points[Line.Points.Count - 1], Preview, PlotPointPictureBox, Algorithm.InverseColor(LineColorPictureBox.BackColor), LineWidthTrackBar.Value);
                    }
                    PolyLineDrawing.DrawPoints(Preview, PlotPointPictureBox, Algorithm.InverseColor(PointColorPictureBox.BackColor), PointWidthTrackBar.Value);
                    PolyLineDrawing.DrawFonts(Preview, Convert.ToString(Line.Points.Count + 1), PlotPointPictureBox, FontColorPictureBox.BackColor, FontStyleDisplayLabel.Font, PointWidthTrackBar.Value);
                    PlotPointPictureBox.Invalidate();
                }

                //编辑
                if (!IsDrawing && IsEditing && !IsPointMoving && Line.Points.Count != 0)
                {
                    PlotPointPictureBox.Cursor = Cursors.Arrow;
                    List <double> Dis     = new List <double>();
                    PlotPoint     EditPos = new PlotPoint
                    {
                        X = e.X,
                        Y = e.Y
                    };

                    foreach (PlotPoint Point in Line.Points)
                    {
                        Dis.Add(Algorithm.GetSingleLineLength(EditPos, Point));
                    }

                    //找最小距离点
                    double MinDistance      = Dis[0];
                    int    MinDistanceIndex = 0;
                    for (int i = 0; i < Dis.Count; i++)
                    {
                        if (Dis[i] < MinDistance)
                        {
                            MinDistance      = Dis[i];
                            MinDistanceIndex = i;
                        }
                    }

                    //小于容差则选中
                    if (MinDistance < Convert.ToDouble(ToleranceTextBox.Text))
                    {
                        IsPointSelected            = true;
                        PlotPointPictureBox.Cursor = CrossCur;
                        SelectedPointIndex         = MinDistanceIndex;
                        DrawingTipLabel.Text       = "已选中第" + Convert.ToString(SelectedPointIndex + 1) + "个点,按住鼠标左键拖动以改变位置,按Del或鼠标右键删除";
                        PolyLineDrawing.DrawPoints(Line.Points[SelectedPointIndex], PlotPointPictureBox, Algorithm.InverseColor(PointColorPictureBox.BackColor), Convert.ToInt32(PointWidthTrackBar.Value * 1.5));
                        PlotPointPictureBox.Refresh();
                    }
                    else
                    {
                        if (SelectedPointIndex != -1)
                        {
                            ClearAndDraw();
                        }
                        DisSelect();
                        DrawingTipLabel.Text = "未选中任何点";
                    }
                }

                //移动选中点
                if (!IsDrawing && IsEditing && IsPointMoving && Line.Points.Count != 0)
                {
                    if (e.X >= 0 && e.Y >= 0 && e.X <= PlotPointPictureBox.Width && e.Y <= PlotPointPictureBox.Height)
                    {
                        Line.Points[SelectedPointIndex].X = e.X;
                        Line.Points[SelectedPointIndex].Y = e.Y;
                        ClearAndDraw();
                        DrawingTipLabel.Text = "正在移动第" + Convert.ToString(SelectedPointIndex + 1) + "个点";
                    }
                    else
                    {
                        DisSelect();
                        DrawingTipLabel.Text = "焦点丢失";
                    }
                }
            }
            catch (Exception err)
            {
                MessageBoxes.Error(err.Message);
            }
        }