C語(yǔ)言_源代碼-C_界面編程小結(jié)_第1頁(yè)
C語(yǔ)言_源代碼-C_界面編程小結(jié)_第2頁(yè)
C語(yǔ)言_源代碼-C_界面編程小結(jié)_第3頁(yè)
C語(yǔ)言_源代碼-C_界面編程小結(jié)_第4頁(yè)
C語(yǔ)言_源代碼-C_界面編程小結(jié)_第5頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、第一次C#界面編程備忘總結(jié)1、 給一個(gè)按鈕“瀏覽”增加save/open-Dialog對(duì)話框“瀏覽”中的程序:/僅僅是把對(duì)話框讀到的路徑顯示到openPath.Text中去if (openFileDialog1.ShowDialog() = DialogResult.OK) openPath.Text = openFileDialog1.FileName;/通過open-Dialog的FileOk事件(點(diǎn)擊保存或雙擊文件)打開某種文件using System.DiagnosticsProcess pro = new Process();pro.Start(); 2、 MessageBoxMes

2、sageBox.Show(this, 串口已被占用!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information);“串口.+ Environment.NewLine + . (Environment.NewLine 表示回車)Buttons還有別的組合返回值的使用: /顯示信息框并得到返回值MessageBox.Show(.);返回類型有: DialogResult.Yes/DialogResult.No/DialogResult.Cancel/DialogResult.No 3、 倒計(jì)時(shí)添加個(gè)interval=1000(默認(rèn)單位ms)的定時(shí)器

3、:timer_timeDisplay定義個(gè)時(shí)間的數(shù)組timeDisplay,從界面獲取倒計(jì)時(shí)的總時(shí)間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) t

4、imeDisplay2 = 60; timeDisplay1-; else if (timeDisplay2 = 0 & timeDisplay1 = 0) timeDisplay2 = 60; timeDisplay1 = 59; timeDisplay0-; timer_timeDisplay.Start();./倒計(jì)時(shí)顯示private void timer_timeDisplay_Tick(object sender, EventArgs e) timeSum-; if (timeDisplay2 != 0) timeDisplay2-; timeDisplay.Text = time

5、Display0 + 時(shí) + timeDisplay1 + 分 + timeDisplay2 + 秒; if (timeDisplay2 = 0 & timeDisplay1 != 0) timeDisplay.Text = timeDisplay0 + 時(shí) + timeDisplay1 + 分 + 00 + 秒; timeDisplay1-; timeDisplay2 = 60; if (timeDisplay0 != 0 & timeDisplay1 = 0 & timeDisplay2 = 0) timeDisplay.Text = timeDisplay0 + 時(shí) + 00 + 分 +

6、 timeDisplay2 + 秒; timeDisplay0-; timeDisplay1 = 59; timeDisplay2 = 60; if (timeDisplay0 = 0 & timeDisplay1 = 0 & timeDisplay2 = 0) timer_timeDisplay.Stop(); MessageBox.Show(this, 時(shí)間到,測(cè)試結(jié)束 + Environment.NewLine + 您可選擇其他操作!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); timeDisplay0 = (int)t

7、imeSum; 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(.);/如果有擴(kuò)展名時(shí) if (end start) path = path.Substring(sta

8、rt + 1); else path = path.Substring(start + 1, end - start - 1); return path; 5、 連接已有模版數(shù)據(jù)庫(kù)文件/對(duì)數(shù)據(jù)庫(kù)操作時(shí)要添加public OleDbConnection connData = new OleDbConnectionpublic OleDbCommand cmd = new OleDbCommand();/連接數(shù)據(jù)庫(kù),并寫入通過串口收到的數(shù)據(jù)private void DataToAccess(int times1, string voltage1, string dB_dBm1)cmd.Comman

9、dText = Insert Into testdata(num,voltage,dB_dBm) Values( + times1 + , + voltage1 + , + dB_dBm1 + );cmd.Connection = connData;connData.Open();cmd.ExecuteNonQuery();cmd.Dispose();connData.Close();6、 拷貝模版數(shù)據(jù)庫(kù)文件到用戶指定pathtry/如果目標(biāo)文件已經(jīng)存在7、 將Access文件導(dǎo)入Excel文件要先添加引用/COM/Microsoft Exccel 11.0 Object Librarystr

10、ing header = new string3 num, voltage, dB_dBm ;/建立Excel對(duì)象 /添加表頭myexcel.Cells1, 1 = 采樣時(shí)間間隔:;myexcel.Cells1, 3 = ts.Text + s;myexcel.Cells2, 1 = 采樣總時(shí)間:;myexcel.Cells2, 3 = th.Text + h;for (int colomn = 0; colomn 3; colomn+)myexcel.Cells4, colomn + 1 = headercolomn;/填充數(shù)據(jù)到Excel(從Access第二行開始導(dǎo)入)for (int j

11、 = 0; j 3; j+)myexcel.Cellsi + 4, j + 1 = mytb.Rowsij.ToString();mybook.SaveCopyAs(savepath);mybook.Saved = true;/退出excelmyexcel.Quit();mybook = null;myexcel = null;mysheet = null;GC.Collect();MessageBox.Show(this, 導(dǎo)出EXCEL成功!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information);return true;OleDbConnection connData1 = new OleDbConnectionOleDbCommand cmd1 = new OleDbCommand(SELECT num,voltage,dB_dB

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論