



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第一次C#界面编程备忘总结1、 给一个按钮“浏览”增加save/open-Dialog对话框“浏览”中的程序:/仅仅是把对话框读到的路径显示到openPath.Text中去if (openFileDialog1.ShowDialog() = DialogResult.OK) openPath.Text = openFileDialog1.FileName;/通过open-Dialog的FileOk事件(点击保存或双击文件)打开某种文件using System.DiagnosticsSystem.IO.FileInfo oppen1 = new System.IO.FileInfo(openFileDialog1.FileName);Process pro = new Process();pro.StartInfo.FileName = openFileDialog1.FileName;pro.StartInfo.WorkingDirectory = oppen1.DirectoryName;pro.Start(); 2、 MessageBoxMessageBox.Show(this, 串口已被占用!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information);“串口.+ Environment.NewLine + . (Environment.NewLine 表示回车)Buttons还有别的组合返回值的使用: /显示信息框并得到返回值System.Windows.Forms.DialogResult rt = MessageBox.Show(.);返回类型有: DialogResult.Yes/DialogResult.No/DialogResult.Cancel/DialogResult.No 3、 倒计时添加个interval=1000(默认单位ms)的定时器:timer_timeDisplay定义个时间的数组timeDisplay,从界面获取倒计时的总时间timeSumint timeDisplay = new int3;Int timeSum;/开始中初步处理代码: .timeDisplay0 = (int)timeSum;timeDisplay1 = (int)(60 * (timeSum - timeDisplay0);timeDisplay2 = (int)(60*(60*(timeSum - timeDisplay0) - timeDisplay1);if (timeDisplay2 = 0 & timeDisplay1 != 0) timeDisplay2 = 60; timeDisplay1-; else if (timeDisplay2 = 0 & timeDisplay1 = 0) timeDisplay2 = 60; timeDisplay1 = 59; timeDisplay0-; timer_timeDisplay.Start();./倒计时显示private void timer_timeDisplay_Tick(object sender, EventArgs e) timeSum-; if (timeDisplay2 != 0) timeDisplay2-; timeDisplay.Text = timeDisplay0 + 时 + timeDisplay1 + 分 + timeDisplay2 + 秒; if (timeDisplay2 = 0 & timeDisplay1 != 0) timeDisplay.Text = timeDisplay0 + 时 + timeDisplay1 + 分 + 00 + 秒; timeDisplay1-; timeDisplay2 = 60; if (timeDisplay0 != 0 & timeDisplay1 = 0 & timeDisplay2 = 0) timeDisplay.Text = timeDisplay0 + 时 + 00 + 分 + timeDisplay2 + 秒; timeDisplay0-; timeDisplay1 = 59; timeDisplay2 = 60; if (timeDisplay0 = 0 & timeDisplay1 = 0 & timeDisplay2 = 0) timer_timeDisplay.Stop(); MessageBox.Show(this, 时间到,测试结束 + Environment.NewLine + 您可选择其他操作!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); timeDisplay0 = (int)timeSum; timeDisplay1 = (int)(60 * (timeSum - timeDisplay0); timeDisplay2 = (int)(60*(60*(timeSum - timeDisplay0) - timeDisplay1); 4、 获取路径文件名 private string GetFileName(string path) int start, end; start = path.LastIndexOf(); end = path.LastIndexOf(.);/如果有扩展名时 if (end start) path = path.Substring(start + 1); else path = path.Substring(start + 1, end - start - 1); return path; 5、 连接已有模版数据库文件using System.Data.OleDb;/对数据库操作时要添加using System.Runtime.InteropServices;public OleDbConnection connData = new OleDbConnection (Provider=Microsoft.Jet.OLEDB.4.0;Data Source= + System.Windows.Forms.Application.StartupPath + test.mdb);public OleDbCommand cmd = new OleDbCommand();/连接数据库,并写入通过串口收到的数据private void DataToAccess(int times1, string voltage1, string dB_dBm1)cmd.CommandText = Insert Into testdata(num,voltage,dB_dBm) Values( + times1 + , + voltage1 + , + dB_dBm1 + );cmd.Connection = connData;connData.Open();cmd.ExecuteNonQuery();cmd.Dispose();connData.Close();6、 拷贝模版数据库文件到用户指定pathtrySystem.IO.File.Copy(System.Windows.Forms.Application.StartupPath + test.mdb, path.Text);connData.ConnectionString = Provider=Microsoft.Jet.OLEDB.4.0;Data Source= + path.Text;catch (System.IO.IOException)/如果目标文件已经存在System.IO.File.Copy(System.Windows.Forms.Application.StartupPath + test.mdb, path.Text, true);connData.ConnectionString = Provider=Microsoft.Jet.OLEDB.4.O;Data Source= + path.Text;7、 将Access文件导入Excel文件要先添加引用/COM/Microsoft Exccel 11.0 Object Libraryusing Microsoft.Office.Interop.Excel;public bool DataToExcel(System.Data.DataTable mytb, string savepath)string header = new string3 num, voltage, dB_dBm ;/建立Excel对象 Microsoft.Office.Interop.Excel.Application myexcel;Microsoft.Office.Interop.Excel._Workbook mybook;Microsoft.Office.Interop.Excel._Worksheet mysheet = null;myexcel = new Microsoft.Office.Interop.Excel.ApplicationClass();mybook = myexcel.Workbooks.Add(true);mysheet = (Microsoft.Office.Interop.Excel._Worksheet)mybook.ActiveSheet;/添加表头myexcel.Cells1, 1 = 采样时间间隔:;myexcel.Cells1, 3 = ts.Text + s;myexcel.Cells2, 1 = 采样总时间:;myexcel.Cells2, 3 = th.Text + h;for (int colomn = 0; colomn 3; colomn+)myexcel.Cells4, colomn + 1 = headercolomn;/填充数据到Excel(从Access第二行开始导入)for (int i = 1; i mytb.Rows.Count; i+)for (int j = 0; j 3; j+)myexcel.Cellsi + 4, j + 1 = mytb.Rowsij.ToString();mybook.SaveCopyAs(savepath);mybook.Saved = true;/退出excelmyexcel.Quit();System.Runtime.InteropServices.Marshal.ReleaseComObject(mybook);System.Runtime.InteropServices.Marshal.ReleaseComObject(myexcel);System.Runtime.InteropServices.Marshal.ReleaseComObject(mysheet);mybook = null;myexcel = null;mysheet = null;GC.Collect();MessageBox.Show(this, 导出EXCEL成功!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information);return true;OleDbConnection connData1 = new OleDbConnection (Provider=Microsoft.Jet.OLEDB.4.0;Data Source= + System.Windows.Forms.Application.Startup
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《2025年劳动合同终止协议书》
- 遵守条约合同范本
- 2025年老建筑拆除合同协议
- 维修商业厨具合同范本
- 食堂食品交易合同范本
- 2025企业定期存单质押借款合同模板
- 装卸搬运合同范本
- 木材砍伐劳务合同范本
- 电缆施工合同范本
- 与工人签合同范本
- NB-T10859-2021水电工程金属结构设备状态在线监测系统技术条件
- 呼吸系统疾病所致精神障碍
- 磁悬浮型与普通型离心冷水机组的性能及能耗比较
- 青光眼小梁切除手术
- 口腔种植一期手术
- 严重精神障碍社区随访经验
- 员工团队意识培训课件
- 脱发患者的头皮及头发护理方法
- 小儿推拿手法穴位的全身调理与养生保健
- 警械培训课件
- 中建制冷机组设备吊装工程专项施工方案冷水机组运输及吊装方案
评论
0/150
提交评论