RichTextBox的C#设置插入符位置的WinForms [英] RichTextBox C# Set caret location winforms

查看:130
本文介绍了RichTextBox的C#设置插入符位置的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立用户在其中输入其文本到一个RichTextBox一个聊天应用程序。

I am building a chat application where the user enters its text to a richtextbox.

在丰富的文本框有它说最初的文字:我说:。

In the rich text box there is an initial text which says: "Me: ".

现在,当用户按下Home键我想位于尖号的我说:之后的字符串。因此,对于SHIFT + HOME组合或三重鼠标点击或按Ctrl +左光标等。

Now, when the user press the Home button I want the caret to be located after the "Me: " string. So for Shift+Home combination or for triple mouse click or for Ctrl + left cursor etc..

什么办法可以做到?

我已经试过

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetCaretPos(int X, int Y);

提前

感谢,
盎司。

thanks in advance, Oz.

推荐答案

发现谷歌搜索的财产SelectionProtected

Found it googling on the property SelectionProtected

richTextBoxUserText.Text = INITIAL_TEXT;
richTextBoxUserText.SelectAll();
richTextBoxUserText.SelectionColor = Color.Red;
richTextBoxUserText.SelectionProtected = true;
richTextBoxUserText.SelectionLength = 0;
richTextBoxUserText.SelectionStart = richTextBoxUserText.TextLength + 1;

这篇关于RichTextBox的C#设置插入符位置的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆