有谁知道如何控制 WPF RichTextBox 的插入模式。我想强制 RichTextBox 始终处于覆盖模式而不是插入模式。
John Gresham
问问题
706 次
1 回答
0
不幸的是,似乎没有记录在案的方式来做到这一点。我知道的唯一方法是使用反射,如下所示,但这种技术可以访问 RichTextBox 的内部工作。它适用于当前版本的 WPF,但不能保证它会继续工作,因此使用它需要您自担风险。
PropertyInfo textEditorPropertyInfo = typeof(RichTextBox).GetProperty("TextEditor", BindingFlags.NonPublic | BindingFlags.Instance);
if (textEditorPropertyInfo == null)
throw new NotSupportedException("SetOverwriteable not support on this platform");
object textEditor = textEditorPropertyInfo.GetValue(this, null);
PropertyInfo overtypeModePropertyInfo = textEditor.GetType().GetProperty("_OvertypeMode", BindingFlags.NonPublic | BindingFlags.Instance);
if (overtypeModePropertyInfo == null)
throw new NotSupportedException("SetOverwriteable not support on this platform");
overtypeModePropertyInfo.SetValue(textEditor, true, null);
以上需要在构造函数之后发生。
于 2009-05-23T17:15:32.960 回答