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

【实例截图】

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

}

}

}

}

}

}

}

java绘制铁路线_铁路站场简图绘制软件源码相关推荐

  1. java计算机毕业设计校园疫情防控管理软件源码+数据库+系统+lw文档+部署

    java计算机毕业设计校园疫情防控管理软件源码+数据库+系统+lw文档+部署 java计算机毕业设计校园疫情防控管理软件源码+数据库+系统+lw文档+部署 本源码技术栈: 项目架构:B/S架构 开发语 ...

  2. 基于tutk方案的p2p源码_基于JAVA的局域网文件共享平台P2P实训项目源码(毕业设计 课程设计)...

    [实例简介] 基于JAVA的局域网文件共享平台P2P实训项目源码(毕业设计 课程设计). 可直接运行.做毕业设计.课程设计或者想研究下技术的可以下载学习.需要更多资源的可以关注我. [实例截图] [核 ...

  3. java实现魔方_闲来无事,用java写了一个魔方小程序。附源码 | 学步园

    闲来无事,用java写了一个魔方小程序.附源码 使用三维数组.相对来说还是简单.呵呵. import java.util.ArrayList; import java.util.List; impor ...

  4. 【Java游戏开发合集】毕业设计(附源码+资料+课件)

    为正在准备毕业设计的小伙伴们以及想自学一些Java练手项目,小编终于整理出了本套视频课程(附源码+资料+课件),快来白嫖吧!!! 视频教程链接: 全站最全Java游戏合集!毕业设计!(附源码课件)8款 ...

  5. 计算机毕业设计Java企业员工考勤系统的设计与实现(源码+系统+mysql数据库+lw文档)

    计算机毕业设计Java企业员工考勤系统的设计与实现(源码+系统+mysql数据库+lw文档) 计算机毕业设计Java企业员工考勤系统的设计与实现(源码+系统+mysql数据库+lw文档) 本源码技术栈 ...

  6. JAVA毕业设计Vue网上书籍购买商城登录计算机源码+lw文档+系统+调试部署+数据库

    JAVA毕业设计Vue网上书籍购买商城登录计算机源码+lw文档+系统+调试部署+数据库 JAVA毕业设计Vue网上书籍购买商城登录计算机源码+lw文档+系统+调试部署+数据库 本源码技术栈: 项目架构 ...

  7. java计算机毕业设计智慧校园学生选宿系统源码+mysql数据库+系统+部署+lw文档

    java计算机毕业设计智慧校园学生选宿系统源码+mysql数据库+系统+部署+lw文档 java计算机毕业设计智慧校园学生选宿系统源码+mysql数据库+系统+部署+lw文档 本源码技术栈: 项目架构 ...

  8. 计算机毕业设计Java校园疫情防控管理软件(源码+系统+mysql数据库+Lw文档)

    计算机毕业设计Java校园疫情防控管理软件(源码+系统+mysql数据库+Lw文档) 计算机毕业设计Java校园疫情防控管理软件(源码+系统+mysql数据库+Lw文档) 本源码技术栈: 项目架构:B ...

  9. 1-基于单片机的城市轨道交通列车超速防护系统_里程表设计(原理图+PCB+源码+仿真工程+答辩论文)

    1-基于单片机的城市轨道交通列车超速防护系统_里程表设计(原理图+PCB+源码+仿真工程+答辩论文) 文章目录 1-基于单片机的城市轨道交通列车超速防护系统_里程表设计(原理图+PCB+源码+仿真工程 ...

最新文章

  1. mac 需要修复你的资源库才能运行应用软件
  2. Jquery中使用JsonP加载本地json文件解决跨域问题
  3. Linux CentOS 6.x设置静态IP(亲测有效)
  4. 全新一代人工智能计算引擎MaxCompute杭州开服,强化阿里云大数据能力,比肩谷歌微软...
  5. JEECG - 基于代码生成器的J2EE智能开发框架 杂记:【演示视频和源码】
  6. 信息学奥赛一本通C++语言——1023:Hello,World!的大小
  7. android 布局 不同屏幕大小,如何创建支持不同屏幕尺寸的Android应用
  8. 基于高斯分布和OneClassSVM的异常点检测
  9. Codeforces7C 扩展欧几里得
  10. 微博千万级规模高性能高并发的网络架构设计
  11. 怎么把字母缩小当符号_iPhone自带输入法怎么用 iPhone自带输入法小技巧【详解】...
  12. el-select数据回显
  13. python的pyaudio教程入门_[宜配屋]听图阁
  14. Forter在Frost Sullivan的2020 Radar报告中被评为电子商务的防欺诈领导者
  15. NAXX Demo4_GZQ_02
  16. matlab分段函数
  17. 【seo伴侣】7种简单的seo技术
  18. 如何在桌面截取gif动态图
  19. 雅思经验(9)之小作文常用词汇总结
  20. lol12.11服务器维护,LOL12月11日测试服更新维护公告 LOL12月11日测试服更新了什么...

热门文章

  1. MT6755/HelioP10处理器性能,MT6755芯片规格资料
  2. html实现网格布局排版整齐的表格,想要排版布局好看又整齐,用网格排一下就行了吗?...
  3. mysql 数据库 back_log 参数
  4. 【技巧分享】【数据分析】数据分析模型
  5. SpringBoot与MongoDB的集成使用
  6. Android百度地图显示POI
  7. 安卓逆向——刷机Pixel2 ROOT
  8. 如何使用Nacos实现配置热更新
  9. HTML + CSS + JavaScript速成
  10. 网络协议学习笔记 · 22