【C#】 打开文件浏览窗口

private   void   openFileDialogBTN_Click(o   b   j   e   c   t   sender,   System.EventArgs   e)
{

  OpenFileDialog openFileDialog=new OpenFileDialog();

  openFileDialog.InitialDirectory="c:\\";

  openFileDialog.Filter="文本文件|*.*|C#文件|*.cs|所有文件|*.*";

  openFileDialog.RestoreDirectory=true;

  openFileDialog.FilterIndex=1;

  if (openFileDialog.ShowDialog()==DialogResult.OK)

  {

  fName=openFileDialog.FileName;

  File fileOpen=new File(fName);

  isFileHaveName=true;

  richTextBox1.Text=fileOpen.ReadFile();

  richTextBox1.AppendText("");

  }

  }
//浏览文件夹

  private void button2_Click(object sender, EventArgs e)

  {

  FolderBrowserDialog dlg = new FolderBrowserDialog();

  if (dlg.ShowDialog() == DialogResult.OK)

  MessageBox.Show(dlg.SelectedPath.ToString());

  }
//打开文件

  private void button3_Click(object sender, EventArgs e)

  {

  OpenFileDialog dlg = new OpenFileDialog();

  if (dlg.ShowDialog() == DialogResult.OK)

  MessageBox.Show(dlg.FileName);

  }

你可能感兴趣的:(C#,小技巧)