/// <summary>
/// 關聯檔案啟動運作時載入檔案
/// </summary>
private void InitalizeLoadFile()
{
string command = Environment.CommandLine;//擷取程序指令行參數
//this.Source.AppendText(command + "\n");
string[] para = command.Split('\"');
// for (int i = 0; i < para.Length; i++) this.Source.AppendText(i+"_lch_" + para[i]+ "\n");
if (para.Length > 4)
{
string pathC = para[3];//擷取打開的檔案的路徑
this.Source.AppendText("0:" + para[0] + "\n");
this.Source.AppendText("1:" + para[1] + "\n");
this.Source.AppendText("2:" + para[2] + "\n");
//this.Source.AppendText("3:" + para[3] + "\n");
//下面就可以自己編寫代碼使用這個pathC參數了
if (pathC.Length > 2)
{
FileStream fs = new FileStream(pathC, FileMode.Open, FileAccess.Read);
this.Source.LoadFile(fs, RichTextBoxStreamType.PlainText);
fs.Close();
}
}
}// 關聯檔案啟動運作時載入檔案
this.Source是richtextbox;
代碼思路來源網上,原本有錯誤,已經修改了。
若使用時,出現異常。可使用for (int i = 0; i < para.Length; i++) this.Source.AppendText(i+"_lch_" + para[i]+ "\n");觀看具體文本,再進行對應操作。
/
直接打開程式内容為:
0_lch_
1_lch_C:\Users\lch\Desktop\記事本\記事本\記事本\bin\Debug\記事本.vshost.exe
2_lch_
輕按兩下打開程式内容為:
0_lch_
1_lch_C:\Users\lch\Desktop\記事本\記事本\記事本\bin\Debug\記事本.exe
2_lch_
3_lch_C:\Users\lch\Desktop\傳回.txt
4_lch_
故做了修改,無修改部分來源于百度知道的回答。