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:
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;
If you want the mousecursor to react at the mouse move, use the following:
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;
The MouseUp is needed, else the cursor won't change back if it hovers above a control.
Be sure to use Screen.Cursor everywhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With