日期:2014-05-17 浏览次数:20827 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 如何打开各种文件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "c:\\";//注意这里写路径时要用c:\\而不是c:\
openFileDialog.Filter = "文本文件|*.*|C#文件|*.cs|所有文件|*.*";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog.FileName;
}
}
private void button1_Click(object sender, EventArgs e)
{
//定义一个ProcessStartInfo实例
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
//设置启动进程的初始目录
info.WorkingDirectory = Application.StartupPath;
//设置启动进程的应用程序或文档名
info.FileName = @textBox1.Text;
//设置启动进程的参数
info.Arguments = "";
//启动由包含进程启动信息的进程资源
try
{
//我在这里是应该怎么指定文件打开第几页呢?
System.Diagnostics.Process.Start(info);
}
catch&nbs