記事本(改進但還不完善)

來源:互聯網
上載者:User

標籤:

 

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 _6._30_對話方塊{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)        {            this.Close();  //關閉視窗        }        private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e)        {            textBox1.Undo();  //撤銷textBox1中的上一個操作        }        private void 剪下TToolStripMenuItem_Click(object sender, EventArgs e)        {            textBox1.Cut();   //剪下--將textBox1中所選內容移動到剪下板中        }        private void 複製CToolStripMenuItem_Click(object sender, EventArgs e)        {            textBox1.Copy();     //複製--將textBox1中所選內容複寫到剪下板中        }        private void 粘貼PToolStripMenuItem_Click(object sender, EventArgs e)        {            textBox1.Paste();     //粘貼--用剪下板中的內容替換textBox1中所選內容        }        private void 全選AToolStripMenuItem_Click(object sender, EventArgs e)        {            textBox1.SelectAll();  //選擇textBox1中全部內容        }        private void textBox1_TextChanged(object sender, EventArgs e)        {            string num = textBox1.TextLength.ToString();    //textBox1中的字數            zishu.Text = num;    //字數顯示        }        private void 字型ToolStripMenuItem_Click(object sender, EventArgs e)        {            fontDialog1.ShowColor = true;  //   顯示顏色            fontDialog1.ShowDialog();        //  開啟            textBox1.Font = fontDialog1.Font;  // 字型改變            textBox1.ForeColor = fontDialog1.Color; // 顏色改變        }        private void 開啟OToolStripMenuItem_Click(object sender, EventArgs e)        {            openFileDialog1.Filter = "文字檔|*.txt"; //限制顯示開啟的檔案類型            DialogResult dr = openFileDialog1.ShowDialog();            if (dr == DialogResult.OK)    //點擊確定            {                StreamReader sr = new StreamReader(openFileDialog1.FileName,UnicodeEncoding.GetEncoding("GB2312"));                textBox1.Text = sr.ReadToEnd();                sr.Close();   //關閉流通道            }        }        string path = "";        private void 儲存SToolStripMenuItem_Click(object sender, EventArgs e)        {            if (path == "")   // 是否已儲存過            {                saveFileDialog1.FileName = "建立文字檔.txt";                saveFileDialog1.ShowDialog();                path = saveFileDialog1.FileName;            }            StreamWriter sw = new StreamWriter(path);            sw.Write(textBox1.Text);            sw.Close();        }        private void 另存新檔AToolStripMenuItem_Click(object sender, EventArgs e)        {            saveFileDialog1.FileName = "建立文字檔.txt";            saveFileDialog1.ShowDialog();            path = saveFileDialog1.FileName;            StreamWriter sw = new StreamWriter(path);            sw.Write(textBox1.Text);            sw.Close();        }        private void 列印設定ToolStripMenuItem_Click(object sender, EventArgs e)        {            pageSetupDialog1.Document = printDocument1; //要列印設定對象是 printDocument1            pageSetupDialog1.ShowDialog();  //開啟對話方塊        }        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)        {    //列印對象            Font f = new Font("宋體", 14);     // 字型格式            Brush b = new SolidBrush(Color.Black);  // 填充的前景色彩為黑色            PointF p = new PointF(10, 10);      // 起始列印位置            e.Graphics.DrawString(textBox1.Text, f, b, p);           // e.Graphics.DrawString(要繪製的字串,字串的文字格式設定,繪製文本的顏色和紋理,繪製文本的左上方位置)        }        private void 預覽列印VToolStripMenuItem_Click(object sender, EventArgs e)        {            printPreviewDialog1.Document = printDocument1;  //要預覽列印對象是 printDocument1            printPreviewDialog1.ShowDialog();        }        private void 列印PToolStripMenuItem_Click(object sender, EventArgs e)        {            printDialog1.Document = printDocument1;   //要列印對象是 printDocument1            printDialog1.ShowDialog();        }    }}

記事本(改進但還不完善)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.