Recent

Author Topic: ScreenToControl on a ScrollBox acts strange.  (Read 2141 times)

jamie

  • Hero Member
  • *****
  • Posts: 6133
ScreenToControl on a ScrollBox acts strange.
« on: January 07, 2019, 12:01:25 am »
doing Scrollbox.ScreenToControl(Mouse.cursorPos) does not seem to account for the scrollbars?

The value I am getting is the same as SCreenToClient which does not care where the scrollbars are in my
Delphi install which does not  account for the scrollbars...

 I would of thought the ScreenToControl in the scrollBox would of done that instead...
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ScrollBox1Click(Sender: TObject);
  2. begin
  3.   With TScrollBox(Sender) do
  4.   begin
  5.    Form1.Caption := (ScreenToClient(Mouse.CurSorPos).X).Tostring
  6.   End;
  7. end;      
  8.  

 So who is or correct here?


P.S.
 I just cheked that with the Form, it also seems to account for the scrollbars...

Hmm, my old Delphi does not nor does it state on the net with the latest if does.

Can someone with recent version of Delphi check this ?

« Last Edit: January 07, 2019, 12:13:52 am by jamie »
The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: ScreenToControl on a ScrollBox acts strange.
« Reply #1 on: January 07, 2019, 12:30:11 am »
Can someone with recent version of Delphi check this ?
I test with code
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ScrollBox1Click(Sender: TObject);
  2. begin
  3.   Caption := IntToStr((Sender as TScrollBox).ScreenToClient(Mouse.CursorPos).x);
  4. end;
Lazarus 2.0.0RC3, Delphi 7, Delphi 10.2. The behavior is the same: shows the visible distance from the left side of the ScrollBox regardless of the position of the horizontal scroll bar.

jamie

  • Hero Member
  • *****
  • Posts: 6133
Re: ScreenToControl on a ScrollBox acts strange.
« Reply #2 on: January 07, 2019, 12:57:10 am »
I tested this with 1.8.4 and it does change..

I dropped a button on the scrollbox to the right so I can force the scrollbar to be visible and thus
move it..
When I click on the upper left corner in my old Delphi install, no matter where the horizontal scrollbar is
I get the same value as if it just returning the ClientRect.Left

 In Lazarus It adds the offset of the H scrollbar to the upper left corner so where ever I move the H bar the
value of scrollbar.Position will be added to the returning value of ScreenToClient(…).X

  I am not exactly sure I understand your answer but is this what you are getting in Delphi 10 or is the value
constant in the upper left corner?


Btw, this was done in the 64 bit 1.8.4

Edit2:
  I just used the LCLINTF.ScreenToClient  instead and it returns what I consider correct, the scrollbar position has
no effect..
  I don't know how long this has bene like this but it bet it has caused lots of issues. The ScreenToControl does the
opposite, it works like the ScreenToClient is suppose do..

« Last Edit: January 07, 2019, 01:20:07 am by jamie »
The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: ScreenToControl on a ScrollBox acts strange.
« Reply #3 on: January 07, 2019, 07:08:55 pm »
I am not exactly sure I understand your answer but is this what you are getting in Delphi 10 or is the value constant in the upper left corner?
Yes, the value from the top left corner is constant. Even if the scrolling position is not zero.
From scrollingwincontrol.inc:
Code: Pascal  [Select][+][-]
  1. function TScrollingWinControl.ScreenToClient(const APoint: TPoint): TPoint;
  2. var
  3.   P: TPoint;
  4. begin
  5.   P := GetClientScrollOffset;
  6.   Result := inherited;
  7.   Result.x := Result.x - P.x;
  8.   Result.y := Result.y - P.y;
  9. end;

jamie

  • Hero Member
  • *****
  • Posts: 6133
Re: ScreenToControl on a ScrollBox acts strange.
« Reply #4 on: January 07, 2019, 10:57:32 pm »
last night before I hit the rack I did some checking for the changes to the 2.0 release and it appears the
Added offset for the TScrollingWinCOntrol was removed to make it Delphi compliant.

 So alarms can now be turned off :D
 
 So I guess we now have two functions that do the same in 2.0
 
    ScreenToClient
    ScreenToControl;

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018