Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Changing the cursor when using the mousedown event

242 views
Skip to first unread message

Bruce Baker

unread,
Sep 5, 2001, 10:31:58 PM9/5/01
to

I want to be able to allow users to manually scroll a large bitmap over an image visual control by dragging the picture with the mouse. When initiating this, at the mousedown stage, a change of the cursor would signal to the user that the action is starting.

However, when I insert code such as:

Image1.Cursor := crHandPoint;

the desired effect does not occur, even if followed by the

Application.ProcessMessages event. Any help will be greatly appreciated.


Quasidata

unread,
Sep 6, 2001, 12:06:39 AM9/6/01
to
Hello Bruce,

{ Save initial cursor }
MyOldCursor :=Application.Cursor;
try
Application.Cursor := crHandPoint;
...
finally
{ Restore the initial cursor}
Application.Cursor :=MyOldCursor;
end;

--
Andrei Fomine.
Add full-blown clipboard and drag-and-drop capabilities to any control with
Transfer@once.
DbAltGrid allows multi-line layout and RTF text in a DBGrid descendant.
http://www.quasidata.com/


"Bruce Baker" <b.a....@xtra.co.nz> wrote in message
news:3b96e01e$1_2@dnews...

Peter Aagaard Kristensen

unread,
Sep 6, 2001, 12:30:35 AM9/6/01
to
>...

> However, when I insert code such as:
> Image1.Cursor := crHandPoint;
> the desired effect does not occur, even if followed by the
> ...
The reason why this does not work is because Delphi captures the mouse when
left-clicking before calling OnMouseDown, and Delphi refuses to change the
mouse when it is captured.
The way to change the mouse when it is captured is:
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
Screen.Cursor := crHandPoint;
end;

On the MouseUp you just set the mouse default again.
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Screen.Cursor := crDefault;
end;

All this only works for left-clicks since Delphi does not capture the mouse
when right-clicking. If you also want this to happen you need to capture the
mouse yourself.
Note that if this is how you plan to change the mouse you should be aware
that OnMouseDown is not always followed by an OnMouseUp event, thus your
cursor migth end up crHandPoint when the mouse is not pressed (e.g. pressing
the mouse then ALT+TAB will result in a Down but not Up).
To resolve this problem you can trap the WM_CAPTURECHANGED message which is
sent when you loose the mouse focus.

Sincerely
Peter Kristensen

Bruce Baker

unread,
Sep 6, 2001, 12:27:36 AM9/6/01
to

"Quasidata" <quasidata AT quasidata DOT com> wrote:
>Hello Bruce,
>
>{ Save initial cursor }
>MyOldCursor :=Application.Cursor;
>try
> Application.Cursor := crHandPoint;
>....

>finally
>{ Restore the initial cursor}
> Application.Cursor :=MyOldCursor;
>end;
>
>--
>Andrei Fomine.
>Add full-blown clipboard and drag-and-drop capabilities to any control with
>Transfer@once.
>DbAltGrid allows multi-line layout and RTF text in a DBGrid descendant.
>http://www.quasidata.com/
>
>
>"Bruce Baker" <b.a....@xtra.co.nz> wrote in message
>news:3b96e01e$1_2@dnews...
I tried using application.cursor but delphi didn't
recognise it. However, using screen.cursor in its
place worked beautifully.

Thank you very much for your help!

0 new messages