A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© mzh901024 中级黑马   /  2013-8-3 19:18  /  1246 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

分享给大家,有不好的地方请指教
----------------------------------------记事本-----------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace MyNotepad
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string path = dialog.FileName;
                StreamWriter sw = new StreamWriter(path); //创建文件写入对象
                string txt=textBox1.Text;  
                sw.Write(txt);  //写入文件
                sw.Close();                 //关闭对象
            }
        }
        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string path = dialog.FileName;
                StreamReader sr = new StreamReader(path,Encoding.Default);//创建文件读取对象
                textBox1.Text = sr.ReadToEnd(); //读取文件内容
                sr.Close();   //关闭文件
            }
        }
    }
}

1 个回复

倒序浏览
值得学习ing!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马