class1.cs

来自「C#开发教程 由浅入深 配有实例 是初学者的好帮手」· CS 代码 · 共 38 行

CS
38
字号
using System;
using System.IO;
using System.Windows.Forms;

namespace FileDialog
{
    class FileDialogApp
    {
        private static OpenFileDialog ofd;

        [STAThread]
        static void Main(string[] args)
        {
            ofd = new OpenFileDialog();
            string s = Path.GetDirectoryName(
                Path.GetDirectoryName(
                Directory.GetCurrentDirectory()));
            
            ofd.InitialDirectory = s;
            ofd.FileOk += 
                new System.ComponentModel.CancelEventHandler(
                ofd_OK);
            ofd.ShowDialog();
        }
        public static void ofd_OK (object sender, 
            System.ComponentModel.CancelEventArgs e)
        {
            StreamReader sr = new StreamReader(ofd.FileName);
            string s;
            while ((s = sr.ReadLine()) != null)
            {
                Console.WriteLine(s);
            }
            sr.Close();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?