發表文章

目前顯示的是有「c#」標籤的文章

[C#]List Box 更改顯示顏色

需求又變更摟 所以要加這東西 cOW!! 先到ListBox的屬性視窗把  DrawMode 修改成 OwnerDrawFixed 然後在LstBox的事件中加入事件函式 如下

[C#]send Email

由於專題的系統要以Email通知管理者系統出錯 所以查了一些資料 通過.Net FrameWork 2.0下提供的“System.Net.Mail”可以輕鬆的實現,本文列舉了3種途徑來發送: 1.通過Localhost; 2.通過普通SMTP; 3.通過SSL的SMTP; 下面一個一個來說:

[C#]播放聲音檔

System.Media. SoundPlayer sp = new System.Media. SoundPlayer (); sp.SoundLocation = @"YourPath\ DoReMe.wav" ; sp.Play(); // 撥放 // sp.Stop(); // 停止

[C#]設定連線Time out

TcpClient MyTcpClient = new TcpClient(); IAsyncResult MyResult = MyTcpClient.BeginConnect(YourTargetIP, YourTargetPort, null, null);  MyResult.AsyncWaitHandle.WaitOne(3000, true);//只等三秒 if (!MyResult.IsCompleted) {     MyTcpClient.Close();     //作如果沒連上線的事 } else if (MyTcpClient.Connected == true) {     //作連上線的事 } MyTcpClient.Close();

[C#]thread 不能直接對控制項取值?

用C#寫windows form 時遇到下列情形 跨執行緒作業無效: 存取控制項 'textBox1' 時所使用的執行緒與建立控制項的執行緒不同。

[C#]取得現在時間

DateTime currentTime = DateTime.NOw; // 取得現在時間 String timeString = currentTime.toString(); //轉成字串

好用的Background Worker

.NET 提供background worker 讓使用者可以很簡單的使用另一條執行緒背景執行程式 (好像是用thread pool實作的) 我就用它來處理我專題的問題 用它來背景接收遠端來的ndb cluster event log 並加入 list box using System.ComponentModel; BackgroundWorker backgroundWorker1; badkgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); private void backgroundWorker1_DoWork(Object sender,DoWorkEventArgs e) { //你要背景執行的CODE }

[c#] 程式資料的設定與config

Visual C # 提供了很容易的設定方法 , 以便程式讀取儲存設定檔,透過setings的介面新增刪除修改config的檔案。其configure檔,儲存為 App.xml ,看副檔名就知道是以xml的形式儲存 以下紀錄我使用的筆記: Visual c#在建立專案時會產生檔,打開該檔可以看到方案總管裡有以下資料properties ->Settings.settings,雙擊後會出現 vc# 提供的介面可以新增 刪除 修改 變數 新增完變數,問題來了 ! 要去哪裡使用 : 其實很簡單只要在程式中加幾行就可以使用了 //使用Config檔 Properties.Settings Config = Properties.Settings.Default; //如果要使用可以直接取出在Settings.settings裡新增的的變數 string test = Config.test; //要修改設定也可以直接修改 Config.test = "this is a test case"; //儲存設定 Config.Save(); 非常的方便