【问题标题】:How to force the insertion mode in a WPF RichTextBox如何在 WPF RichTextBox 中强制插入模式
【发布时间】:2009-05-23 13:52:51
【问题描述】:

有谁知道如何控制 WPF RichTextBox 的插入模式。我想强制 RichTextBox 始终处于覆盖模式而不是插入模式。

【问题讨论】:

    标签: wpf richtextbox


    【解决方案1】:

    不幸的是,似乎没有记录在案的方法可以做到这一点。我知道的唯一方法是使用反射,如下所示,但这种技术可以访问 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);
    

    以上需要在构造函数之后发生。

    【讨论】:

      猜你喜欢
      • 2013-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多