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_dialog
{
public partial class Form1: Form
{
public Form1 ()
{
InitializeComponent ();
}
private void exit XToolStripMenuItem_Click (object sender, EventArgs e)
{
this.Close (); // Close the window
}
private void undo UToolStripMenuItem_Click (object sender, EventArgs e)
{
textBox1.Undo (); // Undo the last operation in textBox1
}
private void cut TToolStripMenuItem_Click (object sender, EventArgs e)
{
textBox1.Cut (); // Cut--Move the selection in textBox1 to the clipboard
}
private void copy CToolStripMenuItem_Click (object sender, EventArgs e)
{
textBox1.Copy (); // Copy--copy the selected content in textBox1 to the clipboard
}
private void paste PToolStripMenuItem_Click (object sender, EventArgs e)
{
textBox1.Paste (); // Paste--Replace the selected content in textBox1 with the content in the clipboard
}
private void Select all AToolStripMenuItem_Click (object sender, EventArgs e)
{
textBox1.SelectAll (); // Select all content in textBox1
}
private void textBox1_TextChanged (object sender, EventArgs e)
{
string num = textBox1.TextLength.ToString (); // Number of words in textBox1
zishu.Text = num; // Word count display
}
private void font ToolStripMenuItem_Click (object sender, EventArgs e)
{
fontDialog1.ShowColor = true; // display color
fontDialog1.ShowDialog (); // open
textBox1.Font = fontDialog1.Font; // font change
textBox1.ForeColor = fontDialog1.Color; // color change
}
private void Open OToolStripMenuItem_Click (object sender, EventArgs e)
{
openFileDialog1.Filter = "Text file | * .txt"; // Restrict display of open file types
DialogResult dr = openFileDialog1.ShowDialog ();
if (dr == DialogResult.OK) // Click OK
{
StreamReader sr = new StreamReader (openFileDialog1.FileName, UnicodeEncoding.GetEncoding ("GB2312"));
textBox1.Text = sr.ReadToEnd ();
sr.Close (); // Close the flow channel
}
}
string path = "";
private void save SToolStripMenuItem_Click (object sender, EventArgs e)
{
if (path == "") // whether it has been saved
{
saveFileDialog1.FileName = "New Text File.txt";
saveFileDialog1.ShowDialog ();
path = saveFileDialog1.FileName;
}
StreamWriter sw = new StreamWriter (path);
sw.Write (textBox1.Text);
sw.Close ();
}
private void Save as AToolStripMenuItem_Click (object sender, EventArgs e)
{
saveFileDialog1.FileName = "New Text File.txt";
saveFileDialog1.ShowDialog ();
path = saveFileDialog1.FileName;
StreamWriter sw = new StreamWriter (path);
sw.Write (textBox1.Text);
sw.Close ();
}
private void print settings ToolStripMenuItem_Click (object sender, EventArgs e)
{
pageSetupDialog1.Document = printDocument1; // The setting object to be printed is printDocument1
pageSetupDialog1.ShowDialog (); // Open dialog
}
private void printDocument1_PrintPage (object sender, System.Drawing.Printing.PrintPageEventArgs e)
{// print object
Font f = new Font ("宋体", 14); // font format
Brush b = new SolidBrush (Color.Black); // The filled foreground color is black
PointF p = new PointF (10, 10); // Start printing position
e.Graphics.DrawString (textBox1.Text, f, b, p);
// e.Graphics.DrawString (string to be drawn, text format of the string, color and texture of the drawn text, upper left corner of the drawn text)
}
private void print preview VToolStripMenuItem_Click (object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1; // The print preview object is printDocument1
printPreviewDialog1.ShowDialog ();
}
private void print PToolStripMenuItem_Click (object sender, EventArgs e)
{
printDialog1.Document = printDocument1; // The object to be printed is printDocument1
printDialog1.ShowDialog ();
}
}
}
Notepad (improved but not yet complete)