發表文章

目前顯示的是 1月, 2009的文章

傳統發送mail VS 多執行緒發送mail

最近要寫一個電子報發送程式,由於可能同時點選多封郵件同時發送,通常會寫一個function呼叫執行,但可能會因為太多郵件造成超時,因此必須改成多執行緒發送郵件 傳統方式 //發送電子報 protected void SendMail() { try { MailAddress fromMail = new MailAddress("發信者信箱", "電子報標題", System.Text.Encoding.UTF8); MailAddress toMail = new MailAddress("收件者信箱", "收件者姓名"); MailMessage message = new MailMessage(fromMail, toMail); message.Subject = cobEName.Text; message.Body = "這裡是電子報發送的內容"; message.IsBodyHtml = true; message.Headers.Add("Disposition-Notification-To", "<回傳的mail>"); SmtpClient mailClient = new SmtpClient("SMTPServer"); mailClient.Credentials = new System.Net.NetworkCredential(txtLoginID.Text, txtLoginPwd.Text);//取得或設定驗證資料 //mailClient.EnableSsl = true;//指定 SmtpClient 是否使用 SSL 加密連線 //mailClient.Port = 587; mailClient.Send(message); } catch (Exception ex) { MessageBox.

正則表達式

正則表達式生來就為了處理字串而活,偏偏卻很難看的懂,例如以下舉例是在檢查E-mail帳號是否正確 var objMail = document.all.txtMail; var rege = /^[\w]+([._-]?[a-z0-9]+)*@[\w]+([._-]?[\w]+)*[\w]$/; if(objMail.length == 0 || rege.exec(objMail .value) == null) { alert('錯誤'); } else { alert('對了'); } 看不懂的話只要多測試,相信應該不會很困難 以下幾個網站可以提供參考 http://caterpillar.onlyfun.net/Gossip/JavaGossip-V1/RegularExpression.htm Java驗證格式 http://momokao.pixnet.net/blog/post/10307155 Java驗證格式 http://www.fboss.com/article.asp?id=683 JavaScript驗證格式 http://annyhunt.pixnet.net/blog/post/537799 JavaScript驗證格式 http://phone.idv.tw/cs2/forums/thread/424.aspx ASP.NET驗證格式

WinForm 背景圖

在winform表單上加上背景圖,並使Label透明,網路上流傳許多像label1.BackColor = System.Drawing.Color.Transparent這樣的語法,其實是不正確的,這樣只是會讓label標籤的背景跟winform表單 一樣的顏色。 在winform繪製背景圖主要有下列三種方式

使用API關閉特定應用程式

在此舉例開啟了一個IE瀏覽器視窗 //關閉IE [DllImport("user32.dll")] public static extern int FindWindow(string strclassName, string strWindowName); [DllImport("user32.dll")] private static extern int SendMessage( int hWnd,   // handle to destination window int Msg,    // message int wParam, // first message parameter int lParam // second message parameter ); const int WM_KEYDOWN = 0x0100; const int WM_KEYUP = 0x0101; const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; private void closeIE() { //dd 為開啟網頁的Title int a = FindWindow("IEFrame", "dd - Microsoft Internet Explorer"); if (a > 0) { SendMessage(a, WM_SYSCOMMAND, SC_CLOSE, 0); } }