• c#记事本


    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 notepads
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            List<string> a = new List<string>();
            private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                OpenFileDialog open = new OpenFileDialog();//创建对话框
                open.InitialDirectory = @"C:Documents and SettingsAll Users桌面"; //设置对话框路径
                open.Title = "对话框1"; //对话框标题
                open.Filter = "文本文档|*.txt|所有文件|*.*";
                open.Multiselect = true; //多选
                open.ShowDialog(); //打开对话框
                //string[] paths = open.FileName;
                string paths = open.FileName;  //读取文件的全路径
                if (paths == "") return;
                using (FileStream file = new FileStream(paths, FileMode.OpenOrCreate, FileAccess.Read))
                {
                    byte[] bytes = new byte[1024 * 1024 * 5];
                    int r = file.Read(bytes, 0, bytes.Length);
                    this.textBox1.Text = Encoding.Default.GetString(bytes, 0, r);
                }
                
                    string ax = Path.GetFileName(paths);
                    listBox1.Items.Add(ax);
                    a.Add(paths);
                
            }
    
            private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                SaveFileDialog sd = new SaveFileDialog(); //创建
                // 保存文件对话框
                sd.InitialDirectory = @"C:Documents and SettingsAll Users桌面"; //设置对话框路径
                sd.Title = "对话框1"; //对话框标题
                sd.Filter = "文本文档|*.txt|所有文件|*.*";
                sd.ShowDialog();
                string path = sd.FileName;
                if (path == "") return;
                using (FileStream fsv = new FileStream(path, FileMode.Create, FileAccess.Write))
                {
                    byte[] bytes = Encoding.Default.GetBytes(this.textBox1.Text);
                    fsv.Write(bytes, 0, bytes.Length);
                }
    
            }
    
            private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (this.textBox1.WordWrap == true)
                {
                    this.textBox1.WordWrap = false;
                }
                else {
    
                    this.textBox1.WordWrap = true;
                }
            }
    
            private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                FontDialog fonts = new FontDialog();
    
                fonts.ShowDialog();
                this.textBox1.Font = fonts.Font;
            }
    
            private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ColorDialog color = new ColorDialog();
                color.ShowDialog();
                this.textBox1.ForeColor = color.Color;
            }
    
            private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
            {
               
              
                      panel1.Show();
                   
            }
    
           
    
            private void Form1_Load(object sender, EventArgs e)
            {
                //string[] path = Directory.GetFiles(@"C:Documents and SettingsAll Users桌面", "*.txt");
               
               
            }
    
            private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
               
            }
    
            private void 隐藏ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                panel1.Hide();
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
               
            }
    
            private void listBox1_DoubleClick(object sender, EventArgs e)
            {
                string name = a[listBox1.SelectedIndex];
                using (FileStream file = new FileStream(name, FileMode.OpenOrCreate, FileAccess.Read))
                {
                    byte[] bytes = new byte[1024 * 1024 * 5];
                    int r = file.Read(bytes, 0, bytes.Length);
                    this.textBox1.Text = Encoding.Default.GetString(bytes, 0, r);
                }
                this.textBox2.Text = a[listBox1.SelectedIndex];
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string pat = this.textBox2.Text;
                
                //File.Delete(pat);
            }
        }
    }
    

      

  • 相关阅读:
    假如我那时再努力点
    C语言经典算法100例-030-判断一个数是否为回文数
    C语言经典算法100例-029-求一个整数的位数且逆序打印
    C语言经典算法100例-028-五个人问岁数
    Abap-Smartforms中如何去掉开头的中文文本
    C语言经典算法100例-027-用递归逆序输出字符
    逐梦之路充满艰辛
    C语言经典算法100例-026-递归求阶乘
    C语言经典算法100例-025-求1+2!+3!+...+20!的和
    集合类Set、Map
  • 原文地址:https://www.cnblogs.com/mengluo/p/5477147.html
Copyright © 2020-2023  润新知