如何在VS中,用C#显示文件打开窗口??

2024-12-13 11:41:58
推荐回答(5个)
回答1:

string path = "controlKeyboard.exe"; //将文件存放在bin目录下 //string path = "D:\\controlKeyboard.exe"; //调用非bin目录下的程序路径 ProcessStartInfo startinfo = new ProcessStartInfo(path); startinfo.WindowStyle = ProcessWindowStyle.Normal; Process.Start(startinfo);这段代码可以打开一个打包好的应用程序,如exe文件同样也可以一个文件夹或者一个word文档之类的

回答2:

string path = "controlKeyboard.exe"; //将文件存放在bin目录下//string path = "D:\\controlKeyboard.exe"; //调用非bin目录下的程序路径ProcessStartInfo startinfo = new ProcessStartInfo(path);startinfo.WindowStyle = ProcessWindowStyle.Normal;Process.Start(startinfo);上面的代码可以打开一个已经打包好的应用程序,如exe后缀的程序

回答3:

OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "打开(Open)"; ofd.FileName = ""; ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments ofd.Filter = "文本文件(*.txt)|*.txt"; ofd.ValidateNames = true; ofd.CheckFileExists = true; ofd.CheckPathExists = true; try { if (ofd.ShowDialog() == DialogResult.OK) { StreamReader sr = new StreamReader(ofd.FileName, System.Text.Encoding.Default); this.richTextBox1.Text = sr.ReadToEnd(); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }

回答4:

结贴给分如果给的不好请别见怪哦,我只是想有劳就有得,嘿嘿...

回答5:

太感谢各位的帮助了...都回答的这么好,可惜我的分就那么一点点,嘿嘿....谢谢各位的帮忙拉!!