我想要“按下”键的那一刻在 WPF 中的 PreviewKeyDown 事件中

发布于 2024-09-27 02:59:15 字数 645 浏览 6 评论 0原文

当我跳到 PreviewKeyDown 时,我的 RichTextBox 中插入符右侧的字符尚未移动。我想说的是,对于这个事件,你的东西将字符移到右侧,然后让我做我的事情。我怎样才能做到这一点?

private void RTB_PreviewKeyDown(object sender, KeyEventArgs e)
 {
    if (e.Key == Key.Space)
    {
       // event do your stuff

       // Char righthanded from the Caret position is moved to the right side

       // do MY stuff
    }

}

更新:你知道我在说什么... =>

alt text

插入符号位于单词“Harold...”之前,然后我按了几次空格键来移动“哈罗德……”在右边。但是黑色下划线的格式似乎被卡住了...我怎样才能使下划线保持附加到包含名称“Harold...”的 Run 对象?

我想在 KeyDown 事件中捕获空格键的原因是为了获取新的隐式创建的 Run-object 并删除黑色下划线。

when I jump into the PreviewKeyDown the char righthand to the Caret in my RichTextBox is not moved YET. I would like to say to this event do your stuff move the char to the rightside and THEN let me do MY stuff. How can I do that?

private void RTB_PreviewKeyDown(object sender, KeyEventArgs e)
 {
    if (e.Key == Key.Space)
    {
       // event do your stuff

       // Char righthanded from the Caret position is moved to the right side

       // do MY stuff
    }

}

UPDATE: that you know what I talk about... =>

alt text

The Caret was directly before the Word "Harold..." then I pressed the spacebar key several times to move the "Harold..." to the right. But the formatting a black Underline seem to be stuck... how can I make the Underline stay attached to the Run object containing the name "Harold..." ?

The reason why I wanted to catch the spacebar key in the KeyDown event is to get the new implicit created Run-object and remove the black Underline.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苦笑流年记忆 2024-10-04 02:59:15

“预览”事件在事件发生之前触发。处理事件后将触发一个等效的 KeyDown 事件。相反,连接到该事件,您的代码将在 WPF 完成处理按键后运行。

"Preview" events are fired before the event happens. There will be an equivalent KeyDown event that is fired after the event is processed. Wire up to that event instead and your code will run after WPF has completed handling the keypress.

╭⌒浅淡时光〆 2024-10-04 02:59:15

这就是为什么它被称为 PreviewKeyDown...您想要的事件可能是 KeyDown 或 TextChanged

That is why its called PreviewKeyDown... the event you want is probably KeyDown or TextChanged

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文