实例介绍
【实例简介】
【实例截图】
【核心代码】
手机GPS开发
using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Reflection; namespace Inspection { public partial class MainForm : Form { public MainForm() { InitializeComponent(); //读取GPS端口文件,配置端口组件 try { StreamReader sr = new StreamReader(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) "\\Port.dat", System.Text.Encoding.Unicode, false); string strLine = sr.ReadLine();//读取文件中的一行 while (strLine != null)//判断是否为空,表示到文件最后一行了 { string[] lineArr = strLine.Split('='); if (lineArr.Length == 2) { switch (lineArr[0]) { case "SerialPort": serialPort1.PortName = lineArr[1]; break; case "BaudRate": serialPort1.BaudRate = int.Parse(lineArr[1]); break; case "DataBits": serialPort1.DataBits = int.Parse(lineArr[1]); break; case "Parity": switch (lineArr[1]) { case "None": serialPort1.Parity = System.IO.Ports.Parity.None; break; case "Odd": serialPort1.Parity = System.IO.Ports.Parity.Odd; break; case "Even": serialPort1.Parity = System.IO.Ports.Parity.Even; break; case "Mark": serialPort1.Parity = System.IO.Ports.Parity.Mark; break; case "Space": serialPort1.Parity = System.IO.Ports.Parity.Space; break; } break; case "StopBits": switch (lineArr[1]) { case "One": serialPort1.StopBits = System.IO.Ports.StopBits.One; break; case "Two": serialPort1.StopBits = System.IO.Ports.StopBits.Two; break; case "OnePointFive": serialPort1.StopBits = System.IO.Ports.StopBits.OnePointFive; break; } break; } } strLine = sr.ReadLine(); } sr.Close();//关闭流 sr.Dispose(); } catch { MessageBox.Show("读取端口文件失败!"); } //创建界面按钮 //第一行3个 //巡检按钮 ImageButton imageButton_XunJian = new ImageButton(); imageButton_XunJian.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Inspection.xunjian.png")); imageButton_XunJian.Location = new Point( (this.Width-64*3) / 4, 8); imageButton_XunJian.Size = new Size(64, 64); //Hook up into click event imageButton_XunJian.Click = new EventHandler(imageButton_XunJian_Click); this.Controls.Add(imageButton_XunJian); Label xunjianLabel = new Label(); xunjianLabel.Size = new Size(64, 20); xunjianLabel.Location = new Point( (this.Width - 64 * 3) / 4, 74); xunjianLabel.Text = "开始巡检"; xunjianLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; xunjianLabel.ForeColor = Color.FromArgb(255,255,255); this.Controls.Add(xunjianLabel); //巡检任务 ImageButton imageButton_RenWu = new ImageButton(); imageButton_RenWu.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Inspection.Search.png")); imageButton_RenWu.Location = new Point( 2*(this.Width - 64 * 3) / 4 64, 8); imageButton_RenWu.Size = new Size(64, 64); //Hook up into click event imageButton_RenWu.Click = new EventHandler(imageButton_XunJian_Click); this.Controls.Add(imageButton_RenWu); Label renwuLabel = new Label(); renwuLabel.Size = new Size(64, 20); renwuLabel.Location = new Point(2 * (this.Width - 64 * 3) / 4 64, 74); renwuLabel.Text = "任务查询"; renwuLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; renwuLabel.ForeColor = Color.FromArgb(255, 255, 255); this.Controls.Add(renwuLabel); //导航按钮 ImageButton imageButton_DaoHang = new ImageButton(); imageButton_DaoHang.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Inspection.daohang.png")); imageButton_DaoHang.Location = new Point(3 * (this.Width - 64 * 3) / 4 2*64, 8); imageButton_DaoHang.Size = new Size(64, 64); //Hook up into click event imageButton_DaoHang.Click = new EventHandler(imageButton_XunJian_Click); this.Controls.Add(imageButton_DaoHang); Label daohangLabel = new Label(); daohangLabel.Size = new Size(64, 20); daohangLabel.Location = new Point(3 * (this.Width - 64 * 3) / 4 2 * 64, 74); daohangLabel.Text = "定位导航"; daohangLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; daohangLabel.ForeColor = Color.FromArgb(255, 255, 255); this.Controls.Add(daohangLabel); //第二行,3个 //系统信息 ImageButton imageButton_mail = new ImageButton(); imageButton_mail.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Inspection.Mail.png")); imageButton_mail.Location = new Point((this.Width - 64 * 3) / 4, 98); imageButton_mail.Size = new Size(64, 64); //Hook up into click event imageButton_mail.Click = new EventHandler(imageButton_XunJian_Click); this.Controls.Add(imageButton_mail); Label mailLabel = new Label(); mailLabel.Size = new Size(64, 20); mailLabel.Location = new Point((this.Width - 64 * 3) / 4, 164); mailLabel.Text = "系统消息"; mailLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; mailLabel.ForeColor = Color.FromArgb(255, 255, 255); this.Controls.Add(mailLabel); //GPS信号检测 ImageButton imageButton_JianCe = new ImageButton(); imageButton_JianCe.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Inspection.gpstest.png")); imageButton_JianCe.Location = new Point(2 * (this.Width - 64 * 3) / 4 64, 98); imageButton_JianCe.Size = new Size(64, 64); //Hook up into click event imageButton_JianCe.Click = new EventHandler(imageButton_JianCe_Click); this.Controls.Add(imageButton_JianCe); Label JianCeLabel = new Label(); JianCeLabel.Size = new Size(64, 20); JianCeLabel.Location = new Point(2 * (this.Width - 64 * 3) / 4 64, 164); JianCeLabel.Text = "GPS信号"; JianCeLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; JianCeLabel.ForeColor = Color.FromArgb(255, 255, 255); this.Controls.Add(JianCeLabel); //系统设置 ImageButton imageButton_SysSetting = new ImageButton(); imageButton_SysSetting.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Inspection.SystemSetting.png")); imageButton_SysSetting.Location = new Point(3 * (this.Width - 64 * 3) / 4 2 * 64, 98); imageButton_SysSetting.Size = new Size(64, 64); //Hook up into click event imageButton_SysSetting.Click = new EventHandler(imageButton_SysSetting_Click); this.Controls.Add(imageButton_SysSetting); Label SysSetLabel = new Label(); SysSetLabel.Size = new Size(64, 20); SysSetLabel.Location = new Point(3 * (this.Width - 64 * 3) / 4 2 * 64, 164); SysSetLabel.Text = "系统设置"; SysSetLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; SysSetLabel.ForeColor = Color.FromArgb(255, 255, 255); this.Controls.Add(SysSetLabel); } //定时器 private void timer1_Tick(object sender, EventArgs e) { //if (serialPort1.IsOpen) //{ // mGps.SetGPSdata(serialPort1.ReadExisting()); //} } // private void MainForm_Load(object sender, EventArgs e) { //这两句保证按下X就会关闭程序,如果没有只会最小化窗口 this.ControlBox = true; this.MinimizeBox = false; } //窗口关闭事件 private void MainForm_Closed(object sender, EventArgs e) { } //退出程序按钮 private void menuItem1_Click(object sender, EventArgs e) { Application.Exit(); } //系统设置 private void imageButton_SysSetting_Click(object sender, EventArgs e) { SysSetForm mForm = new SysSetForm(this.serialPort1); mForm.Show(); } //线路巡检 private void imageButton_XunJian_Click(object sender, EventArgs e) { } //GPS信号 private void imageButton_JianCe_Click(object sender, EventArgs e) { ShowGPSXinXi mForm = new ShowGPSXinXi(this.serialPort1); mForm.Show(); } } }
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论