【问题标题】:C# EditingCommands.MoveDownByLine.Execute(rTB, null);C# EditingCommands.MoveDownByLine.Execute(rTB, null);
【发布时间】:2023-03-13 11:26:01
【问题描述】:

我的标题中的那一行显示了我必须如何编写命令,这样就不会出现编辑器错误,但这种方式没有任何作用。使用richTextBox1。 MS 在下面显示为正确的格式

RichTextBox rTB = new RichTextBox();

EditingCommands.MoveDownByLine.Execute(null,rTB);

如果我在编辑器中输入以上行,我会收到这些错误

errors 错误 2 参数 2:无法从 'System.Windows.Forms.RichTextBox' 到 'System.Windows.IInputElement' C:\Users\Brock\documents\visual studio 2013\Projects\PlayListRandomizer\PlayListRandomizer\Form1.cs 284 65 PlayListRandomizer

错误 1 ​​最好的重载方法匹配 'System.Windows.Input.RoutedCommand.Execute(对象, System.Windows.IInputElement)' 有一些无效的 参数 C:\Users\Brock\documents\visual studio 2013\Projects\PlayListRandomizer\PlayListRandomizer\Form1.cs 284 21 PlayListRandomizer

某种视觉工作室的东西,我错过了?

【问题讨论】:

    标签: c# visual-studio-2012


    【解决方案1】:

    EditingCommands...Execute() 调用 IInputElement 接口,它是 WPF 的一部分。因此,您应该使用 WPF System.Windows.Controls.RichTextBox,而不是 Windows 窗体 System.Windows.Forms.TextBox

    您可以在表单中创建ElementHost,例如yourElementHost,然后添加WPF RichTextBox。像这样的:

            System.Windows.Controls.RichTextBox rTb = new System.Windows.Controls.RichTextBox();
            yourElementHost.Child = rTb;
    

    【讨论】:

    • 哇,还有很多东西要学,谢谢,我会阅读 WPF,并尝试扩大我的视野。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-29
    相关资源
    最近更新 更多