首页 > Windows开发 > 详细

winform记事本初步实现

时间:2016-12-10 22:53:13      阅读:238      评论:0      收藏:0      [点我收藏+]

技术分享

 public Form1()
        {
            InitializeComponent();
        }

        private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Cut();
        }

        private void 复制CToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Copy();
        }

        private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Paste();
        }

        private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Undo();
        }

        private void 重复RToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Redo();
        }

        private void 全选AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.SelectAll();
        }

        private void toolStripStatusLabel2_Click(object sender, EventArgs e)
        {
            
        }

        private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (richTextBox1.WordWrap)
            {
                自动换行ToolStripMenuItem.Checked = false;
                richTextBox1.WordWrap = false;
                toolStripStatusLabel4.Text = "1";
                toolStripStatusLabel6.Text = richTextBox1.TextLength.ToString();
            }
            else
            {
                自动换行ToolStripMenuItem.Checked = true;
                richTextBox1.WordWrap = true;
            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            toolStripStatusLabel2.Text = richTextBox1.TextLength.ToString();//字符数

            toolStripStatusLabel4.Text = richTextBox1.Lines.Length.ToString();//行号
           
            toolStripStatusLabel6.Text = (richTextBox1.SelectionStart - richTextBox1.GetFirstCharIndexOfCurrentLine()).ToString();//焦点所在列数
        }

        private void richTextBox1_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel6.Text = (richTextBox1.SelectionStart - richTextBox1.GetFirstCharIndexOfCurrentLine()).ToString();//焦点所在列数
            
            int index = richTextBox1.GetFirstCharIndexOfCurrentLine();//GetFirstCharIndexOfCurrentLine()当前行第一个字符的索引
            //GetLineFromCharIndex(index)指定位置的索引行号
            toolStripStatusLabel4.Text = (richTextBox1.GetLineFromCharIndex(index) + 1).ToString();//焦点所在行号
        }

 

winform记事本初步实现

原文:http://www.cnblogs.com/maxin991025-/p/6158158.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!