標籤:
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(); } }}
記事本(改進但還不完善)