delphi – 当鼠标左键按下时,如何更改鼠标光标?
发布时间:2020-12-15 04:21:51 所属栏目:大数据 来源:网络整理
导读:在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 the
在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;)但光标不会改变.当鼠标左键向上,我移动鼠标时,光标没有任何问题. (我最初尝试使用一些Drag& Drop事件和属性,但无法按照我想要的方式工作.) 编辑:澄清所需的行为和格式化的代码. 编辑:谢谢你,Gamecat,但我希望当鼠标左键关闭时光标改变,鼠标移动光标时应该在crDrag和crNoDrop之间来回切换. 解决方法
如果你在OnMouseDown中设置鼠标光标并在OnMouseUp中重置它,任何工作正常:
procedure TForm4.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer); begin Cursor := crCross; end; procedure TForm4.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer); begin Cursor := crDefault; // Or you can restore a saved cursor. end; 如果希望鼠标移动时鼠标光标作出反应,请使用以下命令: procedure TForm4.FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer); begin if ssLeft in Shift then begin if X<100 then Screen.Cursor := crCross else Screen.Cursor := crHourGlass; end else Screen.Cursor := crDefault; // Or you can restore a saved cursor. end; procedure TForm4.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer); begin Screen.Cursor := crDefault; // Or you can restore a saved cursor. end; 需要MouseUp,否则如果光标悬停在控件上方,光标将不会变回. 一定要到处使用Screen.Cursor. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |