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.
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.