免费高清特黄a大片,九一h片在线免费看,a免费国产一级特黄aa大,国产精品国产主播在线观看,成人精品一区久久久久,一级特黄aa大片,俄罗斯无遮挡一级毛片

分享

在WinForm/C#中打開一個文件

 昵稱16756252 2014-04-17

WinForm/C#中打開一個文件,主要是用到進(jìn)程的知識。

下面是一些實例,可以模仿著去實現(xiàn)。

1.          打開文件

private void btOpenFile_Click(object sender, EventArgs e)

{

//定義一個ProcessStartInfo實例

System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();

//設(shè)置啟動進(jìn)程的初始目錄

info.WorkingDirectory = Application.StartupPath;

//設(shè)置啟動進(jìn)程的應(yīng)用程序或文檔名

info.FileName = @"test.txt";

//設(shè)置啟動進(jìn)程的參數(shù)

info.Arguments = "";

//啟動由包含進(jìn)程啟動信息的進(jìn)程資源

try

{

System.Diagnostics.Process.Start(info);

}

catch (System.ComponentModel.Win32Exception we)

{

MessageBox.Show(this, we.Message);

return;

}

}

2.          打開瀏覽器

private void btOpenIE_Click(object sender, EventArgs e)

{

//啟動IE進(jìn)程

System.Diagnostics.Process.Start("IExplore.exe");

}

3.          打開指定URL

方法一:

private void btOpenURL_Click(object sender, EventArgs e)

{

//啟動帶參數(shù)的IE進(jìn)程

System.Diagnostics.Process.Start("IExplore.exe", "http://hi.baidu.com/qinzhiyang");

}

方法二:

private void btOpenURLwithArgs_Click(object sender, EventArgs e)

{

//定義一個ProcessStartInfo實例

System.Diagnostics.ProcessStartInfo startInfo = newSystem.Diagnostics.ProcessStartInfo("IExplore.exe");

//設(shè)置進(jìn)程參數(shù)

startInfo.Arguments = " http://hi.baidu.com/qinzhiyang ";

//并且使進(jìn)程界面最小化

startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;

//啟動進(jìn)程

System.Diagnostics.Process.Start(startInfo);

}

4.          打開文件夾

private void btOpenFolder_Click(object sender, EventArgs e)

{

//獲取收藏夾文件路徑

string myFavoritesPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

//啟動進(jìn)程

System.Diagnostics.Process.Start(myFavoritesPath);

}

5.          打印文件

private void PrintDoc()

{

//定義一個進(jìn)程實例

System.Diagnostics.Process myProcess = new System.Diagnostics.Process();

try

{

//設(shè)置進(jìn)程的參數(shù)

string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

myProcess.StartInfo.FileName = myDocumentsPath + "\\TxtForTest.txt";

myProcess.StartInfo.Verb = "Print";

//顯示txt文件的所有謂詞

foreach (string v in myProcess.StartInfo.Verbs)

MessageBox.Show(v);

       

myProcess.StartInfo.CreateNoWindow = true;

//啟動進(jìn)程

myProcess.Start();

}

catch (Win32Exception e)

{

if (e.NativeErrorCode == ERROR_FILE_NOT_FOUND)

{

MessageBox.Show(e.Message + " Check the path." + myProcess.StartInfo.FileName);

}

else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)

{

MessageBox.Show(e.Message + " You do not have permission to print this file.");

}

}

}

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多