//String to DateTime
DateTime time = DateTime.Parse("2014-09-18");
//DateTime to Stirng
//yyyy = 年 , MM = 月 , dd = 日 , HH = 24小時制(hh = 12小時制) , mm = 分 , ss = 秒
string yy = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");ponchi961 發表在 痞客邦 留言(0) 人氣(80)

1.開啟Visual Studio → 點擊 "新建專案"2.範本選擇Visual C# → "Windows Form 應用程式" → 輸入專案名稱 → 確定3.左邊白色看到的式程式主畫面,右邊有三個比較重要的檔案(1)參考:可加入須參考的原件:例如別人寫好的DLL(2)App.config:可設定系統的參數,也可以設定一些參數讓使用者輸入(3)Form1.cs:目前的主程式(UI)4.於左邊工具列選擇"工具箱" → "通用控制項" → "Button"5.於主視窗上拉出一個Button,畫面右下區塊為此Button的設定項(顏色、大小、對齊等等), 點選閃電符號則是此Button的事件6.於Click事件上連點兩下會進入程式碼並自動建立此事件
ponchi961 發表在 痞客邦 留言(0) 人氣(567)
//讀取文字檔-所有行數以陣列方式
string[] lines = System.IO.File.ReadAllLines(@"C:\Log.txt", Encoding.Default);
//讀取文字檔-將文字檔內容組成string
string text = System.IO.File.ReadAllText(@"C:\Log.txt", Encoding.Default);
//寫入文字檔-參數分別為檔名、是否覆蓋原本檔案(true = no,false = yes)、文字編碼
using (System.IO.StreamWriter file = new System.IO.StreamWriter((@"C:\Log.txt", false, Encoding.Default))
{
file.WriteLine("TEST");
}
ponchi961 發表在 痞客邦 留言(0) 人氣(2,951)
浮點數除以整數必須先將整數轉換為浮點數sample:
double doubleNum = 3.2;
int intNum = 6;
double result = doubleNum / (double)intNum ;
ponchi961 發表在 痞客邦 留言(0) 人氣(302)
//選擇資料夾路徑
FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog();
this.txtPath.Text = path.SelectedPath;
//選擇檔案路徑
OpenFileDialog file = new OpenFileDialog();
file.ShowDialog();
this.txtFile.Text = file.SafeFileName;
ponchi961 發表在 痞客邦 留言(0) 人氣(10,060)
ponchi961 發表在 痞客邦 留言(0) 人氣(197)
"呼叫執行緒無法存取此物件,因為此物件屬於另一個執行緒"
若呼叫的Function或執行序內有呼叫UI請使用此方法呼叫。
ps.方法內的Code執行時會lock視窗
this.Dispatcher.Invoke((Action)(() =>
{
// your code or function here.
}));
ponchi961 發表在 痞客邦 留言(0) 人氣(4,453)
//儲存檔案前用此方法建立路徑的資料夾,避免發生路徑不存在Exception。
string fileName = @"C:\Temp\Test.txt";
FileInfo fileInfo = new FileInfo(fileName);
if (fileInfo.Directory.Exists == false)
{
fileInfo.Directory.Create();
}
ponchi961 發表在 痞客邦 留言(0) 人氣(1,493)