在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → 铁路站场简图绘制软件源码

铁路站场简图绘制软件源码

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:2.77M
  • 下载次数:28
  • 浏览次数:339
  • 发布时间:2020-12-25
  • 实例类别:C#语言基础
  • 发 布 人:18036658613
  • 文件格式:.zip
  • 所需积分:1
 相关标签: 软件 绘图

实例介绍

【实例简介】绘制站场简图

【实例截图】

from clipboard

from clipboard

【核心代码】  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("保存失败!");

                        }

                    }

                }

            }
         
        }
    }
}

标签: 软件 绘图

实例下载地址

铁路站场简图绘制软件源码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警