public Form1 ()
{
InitializeComponent ();
}
private void cut TToolStripMenuItem_Click (object sender, EventArgs e)
{
richTextBox1.Cut ();
}
private void copy CToolStripMenuItem_Click (object sender, EventArgs e)
{
richTextBox1.Copy ();
}
private void paste PToolStripMenuItem_Click (object sender, EventArgs e)
{
richTextBox1.Paste ();
}
private void undo UToolStripMenuItem_Click (object sender, EventArgs e)
{
richTextBox1.Undo ();
}
private void Repeat RToolStripMenuItem_Click (object sender, EventArgs e)
{
richTextBox1.Redo ();
}
private void Select all AToolStripMenuItem_Click (object sender, EventArgs e)
{
richTextBox1.SelectAll ();
}
private void toolStripStatusLabel2_Click (object sender, EventArgs e)
{
}
private void Wrap ToolStripMenuItem_Click (object sender, EventArgs e)
{
if (richTextBox1.WordWrap)
{
Word wrap ToolStripMenuItem.Checked = false;
richTextBox1.WordWrap = false;
toolStripStatusLabel4.Text = "1";
toolStripStatusLabel6.Text = richTextBox1.TextLength.ToString ();
}
else
{
Word wrap ToolStripMenuItem.Checked = true;
richTextBox1.WordWrap = true;
}
}
private void richTextBox1_TextChanged (object sender, EventArgs e)
{
toolStripStatusLabel2.Text = richTextBox1.TextLength.ToString (); // Number of characters
toolStripStatusLabel4.Text = richTextBox1.Lines.Length.ToString (); // Line number
toolStripStatusLabel6.Text = (richTextBox1.SelectionStart-richTextBox1.GetFirstCharIndexOfCurrentLine ()). ToString (); // The number of columns of focus
}
private void richTextBox1_Click (object sender, EventArgs e)
{
toolStripStatusLabel6.Text = (richTextBox1.SelectionStart-richTextBox1.GetFirstCharIndexOfCurrentLine ()). ToString (); // The number of columns of focus
int index = richTextBox1.GetFirstCharIndexOfCurrentLine (); // GetFirstCharIndexOfCurrentLine () index of the first character of the current line
// GetLineFromCharIndex (index) specifies the index line number of the position
toolStripStatusLabel4.Text = (richTextBox1.GetLineFromCharIndex (index) + 1) .ToString (); // The line number where the focus is
}
WinForm Notepad Initial implementation