c#記事本

來源:互聯網
上載者:User

標籤:

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 Settings\All 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 Settings\All 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 Settings\All 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#記事本

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.