如何防止光标“跳动”当您键入时进入文本框

发布于 2024-09-15 11:55:51 字数 175 浏览 3 评论 0原文

如果您将焦点放在文本框上,但鼠标光标没有完全悬停在其上,则鼠标光标具有默认箭头形状或您定义的任何形状。

当您开始输入时,鼠标光标会自行隐藏,您只能在文本框中看到闪烁的 IBeam 类型光标。

问题:即使开始打字,如何将鼠标光标保持在初始位置?

有趣的是:这在 WPF 应用程序中不会发生。

If you have a focus on a textbox but mousecursor not exactly hovering on it, mousecursor has default arrow shape or whatever you define.

At the time when you start typing, mousecursor hide itself and you see only blinking stick IBeam type cursor in the textbox.

Question: How to hold mousecursor on its initial position even if you start typing?

Interestingly enough: this doesn't happen in WPF apps.

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

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

发布评论

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

评论(4

少女的英雄梦 2024-09-22 11:55:51

伙计们……这太简单了。在 TextBox.KeyDown 中,我每次都必须移动光标以指向之前的位置。

 Cursor.Position = new Point( oldX, oldY ); 

这里唯一难看的事情 - 如果它是动画光标,动画每次都会重新开始。而且你不能同时打字和移动鼠标。那
有点糟糕,但另一方面谁在乎呢? Winform 应用程序往往比 WPF 应用程序更丑,不是吗?

Guys... That was ridiculously easy. In TextBox.KeyDown I have to move the Cursor every time to point where it was before..

 Cursor.Position = new Point( oldX, oldY ); 

The only ugly thing here - if it's an animated cursor, animation starts everytime all over again. And also you can't type and move the mouse at the same time. That
's kind'a suck, on the other hand who cares? Winform apps tend to be uglier than WPF ones, isn't that true?

假装不在乎 2024-09-22 11:55:51

我来回答一下这个问题。副作用和影响是您的责任。还有另一种方法吗?我确定。

创建一个“状态”变量来保存用户是否正在打字的状态。文本框有各种事件让您知道有人正在输入,EN_CHANGE 等,整个事件系列等等。当用户键入时将状态变量设置为 true。未输入时为 False,EN_LOSTFOCUS 等。

通过 PreProcessMessage 事件或 PreTranslateMessage 事件或任何看起来合适的事件捕获鼠标输入。

当状态变量为 true 时,在 OnPaint 事件中调用“ShowCursor”或可能的“SetCursor”。是的,毛茸茸的,嗯。当状态变量为 false 时不要调用它。

之后调试、调试、再调试。 HTH

如果这不是很清楚的帖子,我会扩展我的答案。

I'm going to answer the question. The side-effects and repercussions are your responsibility. Is there another way of doing it? I'm certain.

Create a "state" variable to hold the state of whether a user is typing or not. Textboxes have various events to let you know when someone is typing, EN_CHANGE, etc., that whole family of events and so on. Set state variable true when user is typing. False when not typing, EN_LOSTFOCUS, etc.

Trap mouse input through a PreProcessMessage event or PreTranslateMessage event, or any that seem appropriate.

Call "ShowCursor" or potentially "SetCursor" in the OnPaint event whilst the state variable is true. Yep, hairy, eh. Do not call it while the state variable is false.

Debug, debug, debug after this. HTH

If this is not clear post and I'll expand my answer.

青朷 2024-09-22 11:55:51

这是 Windows 设置。

在“控制面板”下,转到“鼠标”,然后您应该会看到类似于“键入时隐藏指针”的设置

This is a Windows setting.

Under Control Panel, go to Mouse and then you should see a setting similar to "Hide Pointer While Typing"

内心激荡 2024-09-22 11:55:51

据我所知,没有办法做到这一点。即使关闭 Windows“键入时隐藏指针”设置,如果光标不仅位于文本框上,而且位于整个表单上,光标也会消失。

文本框控件或表单的属性中似乎没有任何内容会影响此行为。

Far as I know, there's no way to do that. Even after turning off the Windows "Hide Pointer While Typing" setting, the cursor will disappear if it is positioned over not just the textbox, but the entire form.

There doesn't seem to be anything in the properties of either the textbox control or the form that affects this behaviour.

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