• winfrom文本文档打开


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.IO;//导入命名空间
    
    namespace WindowsFormsApplication4
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
    
            private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
            {
    
            }
    
            private void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
            {
    
            }
    
            private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e)
            {
                textBox1.Cut();
            }
    
            private void 复制CToolStripMenuItem_Click(object sender, EventArgs e)
            {
                textBox1.Copy();
            }
    
            private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e)
            {
                textBox1.Paste();
            }
    
            private void 全选AToolStripMenuItem_Click(object sender, EventArgs e)
            {
                textBox1.SelectAll();
            }
    
            private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e)
            {
                textBox1.Undo();
            }
    
            private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
            {
                //创建打开文件对话框:实现硬盘上查找文件路径
               // OpenFileDialog openfiledialong1=new OpenFileDialog();//创建对象
                //可以在界面上造一个openfiledialog对象F大写
                openFileDialog1.Filter = "文本文档|*.txt|所有文件|*.*";//过滤
                DialogResult isok = openFileDialog1.ShowDialog();  //显示对话框  枚举类型的返回值
                if (isok == DialogResult.OK)//来通过对话框的返回值判断是否点的打开
                { 
                    //获取文件路径
                    string filename = openFileDialog1.FileName;
                    //根据文件路径读取文件:使用流来读取   流:专门用于内盘跟英寸去交互、读写的
                    //FileStream fs = new FileStream(filename,FileMode.Open );
                    //StreamReader sr = new StreamReader(fs,Encoding.Default);//流读取器
                    StreamReader sr = new StreamReader(filename, Encoding.Default);
                    string text = sr.ReadToEnd();//读取
                    sr.Close();
                   // fs.Close();
    
                    textBox1.Text = text;
                }
            }
        }
    }

      

  • 相关阅读:
    nginx设置屏蔽,可访问id的方法
    python实现rcp远程调用介绍
    0.0.0.0
    datetime 模块详解 -- 基本的日期和时间类型
    python函数——形参中的:*args和**kwargs
    时间加一天,一个小时得到新的时间
    good blog
    Python-第三方库requests详解
    python requests的content和text方法的区别
    MyEclipse使用总结——设置MyEclipse开发项目时使用的JDK
  • 原文地址:https://www.cnblogs.com/zhuxu/p/4966723.html
Copyright © 2020-2023  润新知