在WinForm/C#中打开一个文件,主要是用到进程的知识。
来源:互联网 发布:java实用教程第三版pdf 编辑:程序博客网 时间:2024/05/21 06:34
下面是一些实例,可以模仿着去实现。
1. 打开文件
privatevoid btOpenFile_Click(object sender,EventArgs e)
{
//定义一个ProcessStartInfo实例
System.Diagnostics.ProcessStartInfo info =new System.Diagnostics.ProcessStartInfo();
//设置启动进程的初始目录
info.WorkingDirectory =Application.StartupPath;
//设置启动进程的应用程序或文档名
info.FileName = @"test.txt";
//设置启动进程的参数
info.Arguments = "";
//启动由包含进程启动信息的进程资源
try
{
System.Diagnostics.Process.Start(info);
}
catch (System.ComponentModel.Win32Exception we)
{
MessageBox.Show(this, we.Message);
return;
}
}
2. 打开浏览器
privatevoid btOpenIE_Click(object sender,EventArgs e)
{
//启动IE进程
System.Diagnostics.Process.Start("IExplore.exe");
}
3. 打开指定URL
方法一:
privatevoid btOpenURL_Click(object sender,EventArgs e)
{
//启动带参数的IE进程
System.Diagnostics.Process.Start("IExplore.exe","http://hi.baidu.com/crong21");
}
方法二:
privatevoid btOpenURLwithArgs_Click(object sender,EventArgs e)
{
//定义一个ProcessStartInfo实例
System.Diagnostics.ProcessStartInfo startInfo =newSystem.Diagnostics.ProcessStartInfo("IExplore.exe");
//设置进程参数
startInfo.Arguments = " http://hi.baidu.com/crong21";
//并且使进程界面最小化
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
//启动进程
System.Diagnostics.Process.Start(startInfo);
}
4. 打开文件夹
privatevoid btOpenFolder_Click(object sender,EventArgs e)
{
//获取“收藏夹”文件路径
string myFavoritesPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
//启动进程
System.Diagnostics.Process.Start(myFavoritesPath);
}
5. 打印文件
privatevoid PrintDoc()
{
//定义一个进程实例
System.Diagnostics.Process myProcess =new System.Diagnostics.Process();
try
{
//设置进程的参数
string myDocumentsPath =Environment.GetFolderPath(Environment.SpecialFolder.Personal);
myProcess.StartInfo.FileName = myDocumentsPath +"\\TxtForTest.txt";
myProcess.StartInfo.Verb ="Print";
//显示txt文件的所有谓词
foreach (string vin myProcess.StartInfo.Verbs)
MessageBox.Show(v);
myProcess.StartInfo.CreateNoWindow =true;
//启动进程
myProcess.Start();
}
catch (Win32Exception e)
{
if (e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
MessageBox.Show(e.Message +" Check the path." + myProcess.StartInfo.FileName);
}
elseif (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
MessageBox.Show(e.Message +" You do not have permission to print this file.");
}
}
}
- 在WinForm/C#中打开一个文件,主要是用到进程的知识。
- WinForm/C#中打开一个文件,主要是用到进程的知识。
- C# Winform中打开一个新进程+实例
- 最近在做一个报表系统,c# Winform 用到的一个打印控件
- C# WinForm中如何打开一个超链接
- C# WinForm中如何打开一个超链接
- c# Winform 用到的一个打印控件(VBprinter.DGVprint)。
- C#之WinForm基础 得到文件对话框(一次只能打开一个文件)打开文件的绝对路径
- C# 在一个winform中控制另一个winform中的控件
- C# 在一个winform中控制另一个winform中的控件
- C# WinForm打开PDF文件
- C# WinForm打开PDF文件
- C# WinForm打开PDF文件
- 分享一个简单的资源管理器程序,主要是演示下LINQ在C#开发中的运用
- C# winform中判断文件是否处于打开状态
- 在.net中 每次只能打开一个WinForm应用程序
- 在WinForm 开发中经常用到ListView控件绑定显示DataTable数据,下面记录下主要代码:
- c# 隐藏winform程序在任务管理器中进程
- 松本行弘的程序世界(二)
- 判断一个数是否为素数
- spring自动装配总结
- myeclipse9.1破解方法
- 自己写的Sobel边缘检测程序
- 在WinForm/C#中打开一个文件,主要是用到进程的知识。
- .net升级到4.0之后,出现;System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798
- 关于使用UILocalizedIndexedCollation 实现tableview的边索引
- 在 vi 中替换字符串
- zoj-1088-System Overload
- linux下的共享库(动态库)和静态库
- Android平台上从Camera的jpegquality菜单研究JNI接口
- Spring aop术语概述
- Android Fragment---设计理念