基本信息
源码名称:铁路站场简图绘制软件源码
源码大小:2.77M
文件格式:.zip
开发语言:C#
更新时间:2020-12-25
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 1 元 
   源码介绍
绘制站场简图

  private void pictureBox2_Click(object sender, EventArgs e)
        {
            if (this.getCurrentShapes().Count > 0)
            {
                ArrayList list = new ArrayList();
                string dateHead1 = "insert into Date";
                string dateHead2 = "(type,p1,p2,p3)values(";
                string dateQuotation = "'";
                string dateDot1 = ",";
                string dateDot2 = ")";
                foreach (BaseShape shape in this.getCurrentShapes())

                {
                    string type = shape.GetType().ToString();
                    if (type.Equals("CAD.ArcShape"))
                    {
                        list.Add(dateHead1);
                        list.Add(dateHead2);
                        list.Add(dateQuotation);
                        list.Add(type);
                        list.Add(dateQuotation);
                        list.Add(dateDot1);
                        list.Add(dateQuotation);
                        list.Add(shape.getP1());
                        list.Add(dateQuotation);
                        list.Add(dateDot1);
                        list.Add(dateQuotation);
                        list.Add(shape.getP2());
                        list.Add(dateQuotation);
                        list.Add(dateDot1);
                        list.Add(dateQuotation);
                        list.Add(((ArcShape)shape).getP3());
                        list.Add(dateQuotation);
                        list.Add(dateDot2);

                    }
                    else
                    {
                        list.Add(dateHead1);
                        list.Add(dateHead2);
                        list.Add(dateQuotation);
                        list.Add(type);
                        list.Add(dateQuotation);
                        list.Add(dateDot1);
                        list.Add(dateQuotation);
                        list.Add(shape.getP1());
                        list.Add(dateQuotation);
                        list.Add(dateDot1);
                        list.Add(dateQuotation);
                        list.Add(shape.getP2());
                        list.Add(dateQuotation);
                        list.Add(dateDot1);
                        list.Add(dateQuotation);
                        list.Add(dateQuotation);
                        list.Add(dateDot2);
                    }
                }
                // 创建文件。如果文件存在则覆盖

                saveFileDialog1.Filter = "数据库文件|*.sql|文本文件| *.txt";
                // 创建写入流
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {

                    StreamWriter wr = new StreamWriter(saveFileDialog1.FileName, true);
                    //FileStream fs = File.Open(@"d:\内容.sql", FileMode.Create);
                    //StreamWriter wr = new StreamWriter(fs, System.Text.Encoding.UTF8);
                    // 将ArrayList中的每个项逐一写入文件
                    for (int i = 0; i < list.Count; i )
                    {
                        wr.WriteLine(list[i]);
                    }
                    // 关闭写入流
                    wr.Flush();
                    wr.Close();

                    // 关闭文件
                    //fs.Close();
                }

            }
            else
            {
                MessageBox.Show("当前界面没有图形!");
            }
        }

        private void pictureBox2_Click_1(object sender, EventArgs e)
        {
            if (this.getCurrentShapes().Count > 0)
            {

                saveFileDialog3.Filter = "Jpg 图片|*.jpg|Bmp 图片|*.bmp|Gif 图片|*.gif|Png 图片|*.png|Wmf  图片|*.wmf";
                saveFileDialog3.FileName = System.DateTime.Now.ToString("yyyyMMddHHmmss") "-"; ;//设置默认文件名
                if (saveFileDialog3.ShowDialog() == DialogResult.OK)
                {
                    this.pictureBox1.Image = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
                    Graphics g = Graphics.FromImage(this.pictureBox1.Image);
                    Graphics.FromImage(this.pictureBox1.Image).Clear(Color.White);//消除底图的黑色
                    for (int i = 0; i < currentShapes.Count; i )
                    {
                        string Type = ((BaseShape)currentShapes[i]).GetType().ToString();
                        switch (Type)
                        {
                            case "CAD.LineShape":
                                g.DrawLine(new Pen(((BaseShape)currentShapes[i]).penColor, (float)((((BaseShape)currentShapes[i]).penwidth) * 1.7)),
                                    ((BaseShape)currentShapes[i]).getP1(), ((BaseShape)currentShapes[i]).getP2());
                                Pen p = new Pen(Color.White, (((BaseShape)currentShapes[i]).penwidth));
                                p.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //自定义样式
                                p.DashPattern = new float[] { 7, 5 };
                                g.DrawLine(p, ((BaseShape)currentShapes[i]).getP1(), ((BaseShape)currentShapes[i]).getP2());

                                break;
                            case "CAD.RectangleShape":
                                g.DrawRectangle(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP1().X, ((BaseShape)currentShapes[i]).getP1().Y, (((BaseShape)currentShapes[i]).getP2().X - ((BaseShape)currentShapes[i]).getP1().X), (((BaseShape)currentShapes[i]).getP2().Y - ((BaseShape)currentShapes[i]).getP1().Y));
                                g.DrawRectangle(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP1().X, ((BaseShape)currentShapes[i]).getP2().Y, (((BaseShape)currentShapes[i]).getP2().X - ((BaseShape)currentShapes[i]).getP1().X), (((BaseShape)currentShapes[i]).getP1().Y - ((BaseShape)currentShapes[i]).getP2().Y));
                                g.DrawRectangle(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP2().X, ((BaseShape)currentShapes[i]).getP2().Y, (((BaseShape)currentShapes[i]).getP1().X - ((BaseShape)currentShapes[i]).getP2().X), (((BaseShape)currentShapes[i]).getP1().Y - ((BaseShape)currentShapes[i]).getP2().Y));
                                g.DrawRectangle(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP2().X, ((BaseShape)currentShapes[i]).getP1().Y, (((BaseShape)currentShapes[i]).getP1().X - ((BaseShape)currentShapes[i]).getP2().X), (((BaseShape)currentShapes[i]).getP2().Y - ((BaseShape)currentShapes[i]).getP1().Y));

                                break;
                            case "CAD.EllipseShape":
                                g.DrawEllipse(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP1().X, ((BaseShape)currentShapes[i]).getP1().Y, (((BaseShape)currentShapes[i]).getP2().X - ((BaseShape)currentShapes[i]).getP1().X), (((BaseShape)currentShapes[i]).getP2().Y - ((BaseShape)currentShapes[i]).getP1().Y));
                                break;
                            case "CAD.CircleShape":
                                int r = (int)Math.Pow(Math.Pow(((BaseShape)currentShapes[i]).getP2().X - ((BaseShape)currentShapes[i]).getP1().X, 2) Math.Pow(((BaseShape)currentShapes[i]).getP2().Y - ((BaseShape)currentShapes[i]).getP1().Y, 2), 0.5);
                                g.DrawEllipse(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth), ((BaseShape)currentShapes[i]).getP1().X - r, ((BaseShape)currentShapes[i]).getP1().Y - r, 2 * r, 2 * r);
                                break;
                            case "CAD.ArcShape":
                                DrawArcFromThreePoint(((ArcShape)currentShapes[i]).getP1().X,
                                   ((ArcShape)currentShapes[i]).getP1().Y,
                                   ((ArcShape)currentShapes[i]).getP2().X,
                                   ((ArcShape)currentShapes[i]).getP2().Y,
                                   ((ArcShape)currentShapes[i]).getP3().X,
                                   ((ArcShape)currentShapes[i]).getP3().Y);
                                g.DrawArc(new Pen(((BaseShape)currentShapes[i]).penColor, ((BaseShape)currentShapes[i]).penwidth),
                                    (int)Arcx, (int)Arcy, (int)ArcRadius1, (int)ArcRadius2,
                                    (int)Arcangle1, (int)Arcangle2);
                                break;
                            case "CAD.AssistShape":

                                Point p1 = ((AssistShape)currentShapes[i]).getP1();
                                Point p2 = ((AssistShape)currentShapes[i]).getP2();
                                Point p3 = ((AssistShape)currentShapes[i]).getP3();
                                Pen p_assist1 = new Pen(Color.Green, 0);
                                p_assist1.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //自定义样式
                                p_assist1.DashPattern = new float[] { 2, 1 };
                                g.DrawLine(p_assist1, p1.X, p1.Y, p1.X, p3.Y);
                                g.DrawLine(p_assist1, p2.X, p2.Y, p2.X, p3.Y);
                                g.DrawLine(p_assist1, p1.X, p3.Y, p2.X, p3.Y);

                                break;

                            case "CAD.AssistalignmentShape":
                                Point p4 = ((AssistalignmentShape)currentShapes[i]).getP1();
                                Point p5 = ((AssistalignmentShape)currentShapes[i]).getP2();
                                Point p6 = ((AssistalignmentShape)currentShapes[i]).getP3();
                                Pen p_assist2 = new Pen(Color.Green, 0);
                                p_assist2.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //自定义样式
                                p_assist2.DashPattern = new float[] { 2, 1 };
                                g.DrawLine(p_assist2, p4.X, p4.Y, p6.X, p4.Y);
                                g.DrawLine(p_assist2, p5.X, p5.Y, p6.X, p5.Y);
                                g.DrawLine(p_assist2, p6.X, p4.Y, p6.X, p5.Y);
                                break;

                        }

                    ((BaseShape)currentShapes[i]).superDraw(g);//变幻的时候
                    }
                    this.pictureBox1.Image.Clone();//这句话是关键    //释放此 System.Drawing.Image 使用的所有资源。
                    pictureBox1.Image.Save(saveFileDialog3.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    MessageBox.Show(this, "图片保存成功!", "信息提示");
                }
            }
            else
            {
                MessageBox.Show("当前界面没有图形!");
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)
        {

        }


        private void txt_currenttool_TextChanged(object sender, EventArgs e)
        {

        }

       

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            fontDialog1.ShowColor = true;//这行代码一定要出现在fontDialog1.ShowDialog()之前。
            fontDialog1.ShowDialog();
            foreach (BaseShape shape in currentShapes)
            {
                if (shape.GetType().ToString().Equals("CAD.AssistShape"))
                {
                    
                    ((AssistShape)shape).getTxtAssist().Font = fontDialog1.Font;
                    ((AssistShape)shape).getTxtAssist().ForeColor = fontDialog1.Color;//设置字体颜色
                }
                    
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            bool isSave = true;

            SaveFileDialog saveImageDialog = new SaveFileDialog();

            saveImageDialog.Title = "Capture screen image savedialog";

            saveImageDialog.Filter = @"jpeg|*.jpg|bmp|*.bmp|gif|*.gif";

            if (saveImageDialog.ShowDialog() == DialogResult.OK)

            {

                string fileName = saveImageDialog.FileName.ToString();



                if (fileName != "" && fileName != null)

                {

                    string fileExtName = fileName.Substring(fileName.LastIndexOf(".") 1).ToString();
                   
                    System.Drawing.Imaging.ImageFormat imgformat = null;



                    if (fileExtName != "")

                    {

                        switch (fileExtName)

                        {

                            case "jpg":

                                imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;

                                break;

                            case "bmp":

                                imgformat = System.Drawing.Imaging.ImageFormat.Bmp;

                                break;

                            case "gif":

                                imgformat = System.Drawing.Imaging.ImageFormat.Gif;

                                break;

                            default:

                                MessageBox.Show("只能存取为: jpg,bmp,gif 格式");

                                isSave = false;

                                break;

                        }

                    }

                    //默认保存为JPG格式

                    if (imgformat == null)

                    {
                        imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
                    }

                    if (isSave)

                    {

                        try

                        {
                      
                             pictureBox1.Image.Save(fileName, imgformat);
                            //RealtimeVideoForm.image.Save(fileName, imgformat);

                            MessageBox.Show("图片成功保存!~~");

                        }

                        catch

                        {

                            MessageBox.Show("保存失败!");

                        }

                    }

                }

            }
         
        }
    }
}