简体   繁体   English

单击按钮后如何使光标返回RichTextBox?

[英]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! 另外,我希望光标在程序启动时出现在RichTextBox上(同样,当用户单击我的TabIndex中的该选项卡时。)!谢谢!

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. 焦点使光标出现,而select设置光标应出现的位置。 You only have to set the variable lastPosition yourself 您只需要自己设置变量lastPosition

And to change the default font etc. use this 并更改默认字体等。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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