WinForm Notepad Preliminary implementation

Source: Internet
Author: User
Tags word wrap





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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.