我是靠谱客的博主 聪明薯片,最近开发中收集的这篇文章主要介绍C#编程-120:文件选择之OpenFileDialog控件,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace OpenFileDialogTest
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void btnOpen_Click(object sender, EventArgs e)
  21.         {
  22.             OpenFileDialog ofd = new OpenFileDialog();
  23.             ofd.InitialDirectory = @"C:UserspengshiyuDesktopdestination";
  24.             //设置文件筛选器
  25.             ofd.Filter = "文本文件(*.txt)|*.txt|Word文件(*.doc,*.docx)|*.doc;*.docx|所有文件(*.*)|*.*";
  26.             ofd.FilterIndex = 1;
  27.             ofd.Title = "openFileDialog实例";
  28.             ofd.FileName = "123";
  29.             ofd.ShowHelp = true;
  30.             if (ofd.ShowDialog() == DialogResult.OK)
  31.             {
  32.                 string fName = ofd.FileName;
  33.                 string fileCon = "";
  34.                 StreamReader sr = new StreamReader(fName, Encoding.GetEncoding("gb2312"));
  35.                 while ((fileCon = sr.ReadLine()) != null)
  36.                 {
  37.                     txtShow.Text += fileCon;
  38.                 }
  39.                 sr.Close();
  40.  
  41.             }
  42.         }
  43.     }
  44. }
C#编程-120:文件选择之OpenFileDialog控件 C#编程-120:文件选择之OpenFileDialog控件


最后

以上就是聪明薯片为你收集整理的C#编程-120:文件选择之OpenFileDialog控件的全部内容,希望文章能够帮你解决C#编程-120:文件选择之OpenFileDialog控件所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部