简体   繁体   中英

How do I make the cursor to go back to RichTextBox after clicking a button?

So, I have some style buttons programmed, and I desire that right after the user clicks on a button, the cursor appears right away where he/she was typing before clicking the button. Also, I wish for the cursor to appear right at the RichTextBox when the program is launched (also, when the user clicks on that tab in my TabIndex. Thanks!

Some Code would have been nice to work with but this should give you a hint:

    private void button2_Click(object sender, EventArgs e)
    {
        richTextBox1.Focus();
        richTextBox1.Select(lastPosition, 0);
    }

The focus makes the cursor appear and the select sets the position where the cursor should appear. You only have to set the variable lastPosition yourself

And to change the default font etc. use this 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM