zoukankan      html  css  js  c++  java
  • 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;
                }
            }
        }
    }

      

  • 相关阅读:
    Cocos2d-x教程(26)-Cocos2d-x + Lua脚本实现大地图缩放功能
    【C语言】不使用大小于号,求出两数最大值
    软件project—思考项目开发那些事(一)
    linux下误删数据文件恢复
    C++中stringstream ostringstream istringstream使用方式
    谈谈c++纯虚函数的意义!
    CountDownTimer完整具体演示样例
    Flex 正則表達式 电话、邮箱验证
    DIV+CSS两种盒子模型(W3C盒子与IE盒子)
    图论--欧拉路,欧拉回路(小结)
  • 原文地址:https://www.cnblogs.com/zhuxu/p/4966723.html
Copyright © 2011-2022 走看看