Recent

Author Topic: Local and global mouse cursor settimgs  (Read 895 times)

simsee

  • Full Member
  • ***
  • Posts: 208
Local and global mouse cursor settimgs
« on: February 17, 2024, 07:12:58 pm »
I'm developing an application that requires different mouse cursors depending on the controls it's on. Therefore I did some preliminary experiments and found unexpected behaviors.

To decide which cursor appears over a control, I can set its Cursor property. This setting has a local effect. I can globally set the cursor for all visible controls using Screen.Cursor.

What I noticed is that if I set before Screen.Cursor, after the local settings have no effect. This is shown by the demo program that I attach, in which, with one button you set the global cursor, using Screen.Cursor, with the other the local one of a Panel, with TPanel.Cursor.

Is this behavior correct and expected? Is it possible to set the local cursor on a control after setting the global one? Or do I have to set the cursors of the various controls individually, without touch Screen.Cursor?

Thanks.
« Last Edit: February 17, 2024, 07:22:26 pm by simsee »

jamie

  • Hero Member
  • *****
  • Posts: 6953
Re: Local and global mouse cursor settimgs
« Reply #1 on: February 17, 2024, 08:13:32 pm »
Yup,. That seems to be how I remember it.
The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11342
  • Debugger - SynEdit - and more
    • wiki
Re: Local and global mouse cursor settimgs
« Reply #2 on: February 17, 2024, 10:17:35 pm »
Yes, afaik correct.

But once you do
Code: Pascal  [Select][+][-]
  1. Screen.Cursor:=crDefault;
the local setting will be in effect.

Screen.Cursor overrides all local cursors. You can't have a single control exempt from it.

You can have onMouseEnter/Leave for that control, and change the screen cursor and restore it....

ASerge

  • Hero Member
  • *****
  • Posts: 2419
Re: Local and global mouse cursor settimgs
« Reply #3 on: February 18, 2024, 08:39:20 am »
You can have onMouseEnter/Leave for that control, and change the screen cursor and restore it....
Using existing methods:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Panel1MouseEnter(Sender: TObject);
  2. begin
  3.   Screen.BeginTempCursor((Sender as TControl).Cursor);
  4. end;
  5.  
  6. procedure TForm1.Panel1MouseLeave(Sender: TObject);
  7. begin
  8.   Screen.EndTempCursor((Sender as TControl).Cursor);
  9. end;

 

TinyPortal © 2005-2018