按下鼠标左键时如何更改鼠标光标?
在 Delphi 2007 中,在鼠标移动事件中,我尝试使用以下命令更改鼠标光标:
procedure TFr_Board_Display.PaintBox_Proxy_BoardMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if left_mouse_button_down then begin
if some_condition then begin
Cursor := crDrag;
end
else begin
Cursor := crNoDrop;
end;
end
else begin
if some_other_condition then begin
Cursor := crHandPoint;
end
else begin
Cursor := crDefault;
end;
end;
end;
例如。 但是,当按下鼠标左键并移动鼠标时,光标不会更改为 crDrag 或 crNoDrop。 代码被执行(例如 Cursor := crDrag;),但光标没有改变。 当鼠标左键抬起时,我移动鼠标,光标变化没有问题。
(我最初尝试使用一些拖放事件和属性,但无法让所有内容按照我想要的方式工作。)
编辑:澄清所需的行为和格式化代码。
编辑:谢谢你,Gamecat,但我希望当鼠标左键按下时光标会发生变化,并且当鼠标移动时光标应该在 crDrag 和 crNoDrop 之间来回变化。
In Delphi 2007, in a mouse move event, I try to change the mouse cursor with:
procedure TFr_Board_Display.PaintBox_Proxy_BoardMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if left_mouse_button_down then begin
if some_condition then begin
Cursor := crDrag;
end
else begin
Cursor := crNoDrop;
end;
end
else begin
if some_other_condition then begin
Cursor := crHandPoint;
end
else begin
Cursor := crDefault;
end;
end;
end;
for example. However, when the left mouse button is down, and I move the mouse, the cursor doesn't change to either crDrag or crNoDrop. The code is executed (e.g. Cursor := crDrag;) but the cursor does not change. When the left mouse button is up, and I move the mouse, the cursor changes no problem.
(I originally tried to use some Drag & Drop events and properties, but couldn't get everything to work the way I wanted.)
Edit: Clarified desired behavior, and formatted code.
Edit: Thank you, Gamecat, but I want the cursor to change when the left mouse button is down and the while the mouse is moving the cursor should change back and forth between crDrag and crNoDrop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在 OnMouseDown 中设置鼠标光标并在 OnMouseUp 中重置它,则一切正常:
如果您希望鼠标光标在鼠标移动时做出反应,请使用以下命令:
需要 MouseUp,否则光标将不会变回如果它悬停在控件上方。
请务必在任何地方使用 Screen.Cursor。
If you set the mouse cursor in the OnMouseDown and reset it in the OnMouseUp, anything works fine:
If you want the mousecursor to react at the mouse move, use the following:
The MouseUp is needed, else the cursor won't change back if it hovers above a control.
Be sure to use Screen.Cursor everywhere.
有点偏离主题,但也许对你有用。
我创建了一个全局堆栈以允许嵌套游标更改。 它允许任何代码段将鼠标光标设置为他们想要的位置,而不必担心调用者或被调用者将其设置为什么。
例如:
两个过程都不必担心另一个过程需要什么状态或离开鼠标光标。
Slightly off-topic, but perhaps useful to you.
I created a global stack to allow nested cursor changes. It lets any piece of code set the mouse cursor to what they want without worrying about what their caller or callee's set it to.
For example:
Neither procedure has to worry about what state the other needs or leaves the mouse cursor.