Lazarus

Programming => LCL => Topic started by: spassigl on March 08, 2021, 06:37:54 pm

Title: [SOLVED] Scrollbox horizontal scrollbars now showing up
Post by: spassigl on March 08, 2021, 06:37:54 pm
Hi, I've been trying and searching everything but there's something I'm missing I'm afraid.

On a form, I have a tabbed interface, and inside one of the tabs, I have a TScrollbox.
At run-time, I create my own control to be hosted in the scrollbox. The control is a TWinControl descendant.
Hierarchy is like this:
- TPageControl
  - TTabSheet
     - TScrollbox
        - TGraphicEditor (my component, descendant of TWinControl)

All components except for TGraphicEditor are aligned as alClient.
TGraphicEditor is aligned as alCustom.

I create my component this way:

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.SetupGraphicsEditor;
  2. begin
  3.    GraphicEditor := TGraphicEditor.Create(Self);
  4.    with GraphicEditor do
  5.    begin
  6.       Parent := GraphicalScrollBox;
  7.      Align := alCustom;
  8.      Anchors := [akTop, akLeft, akRight, akBottom];
  9.      Visible := true;
  10.       Width := GraphicalScrollBox.Width;
  11.       Height := GraphicalScrollBox.Height;
  12.       Constraints.MinWidth := GraphicalScrollBox.Constraints.MinWidth;
  13.       Constraints.MinHeight := GraphicalScrollBox.Constraints.MinHeight;
  14.       Resize;
  15.    end;
  16. end;
  17.  

So far so good.

But - there are circumstances when the GraphicEditor becomes bigger than the scrollbox. I'm expecting the scrollbox to show the scrollbars but it does not.
See attached picture.

Anything I'm clearly missing here?

Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: jamie on March 09, 2021, 02:10:32 am
for the scrollbars to show first you need to ensure "AutoScroll" is checked for the TScrollbox…

second, if you are setting the constraints of the child control to the constraints of the scrollbox then I would say you will never see the scrollbars.

 Not sure what your intended use is for the scroll box but its designed to simulate a larger client area than what is being shown so this means child controls that map off the current client size of the scrollbox should make the scrollbars appear and allow you to scroll over and view your child controls..

 if you are looking for something like a ruler then you are using the wrong controls
Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: spassigl on March 09, 2021, 10:16:14 am
Thanks, yes I just want to simulate a larger client area than what is being shown.

Yes Autoscroll is set to True;
I removed the constraints code (even if they were on the min size) but still scrollbars don't appear.
Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: trev on March 09, 2021, 11:34:31 am
Operating system? Widgetset? Lazarus version?
Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: spassigl on March 09, 2021, 12:18:41 pm
Fedora 32 - Linux 5.10.16
GTK2
Lazarus 2.0.10 - FPC 3.2.0
Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: jamie on March 09, 2021, 05:22:06 pm
Did u enable / visible property of the scrollbars to true?
You have two and they need to be visible.
Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: spassigl on March 09, 2021, 05:44:33 pm
Yes, obviously. They are Visible by default and I have not touched them.
Literally, I only dropped the Scrollbox on the form and did not touch anything, apart from setting its alignment to alClient.
I have added some debug info in the OnResize event of my control.  See below.
I have added a button that increases the size of my control of 10px on every click.
Parent is the Scrollbox, Self is my control. As you can see, my control width becomes bigger while the Scrollbox width stays the same. I assume this should show the scrollbars but it's not happening.

Parent size - (t,l,w,h): (0,0,1155,776)
Self size - (t,l,w,h): (0,0,1163,774)
Parent size - (t,l,w,h): (0,0,1155,776)
Self size - (t,l,w,h): (0,0,1173,774)
Parent size - (t,l,w,h): (0,0,1155,776)
Self size - (t,l,w,h): (0,0,1183,774)
Parent size - (t,l,w,h): (0,0,1155,776)
Self size - (t,l,w,h): (0,0,1193,774)
Parent size - (t,l,w,h): (0,0,1155,776)
Self size - (t,l,w,h): (0,0,1203,774)
Parent size - (t,l,w,h): (0,0,1155,776)
Self size - (t,l,w,h): (0,0,1213,774)
Parent size - (t,l,w,h): (0,0,1155,776)
Self size - (t,l,w,h): (0,0,1223,774)
Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: korba812 on March 09, 2021, 06:03:03 pm
Looking at your code, I can say that there is nothing to scroll because your GraphicsEditor always fits into the scrollbox.

To see what the problem is, try this code:
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.SetupGraphicsEditor;
  2. begin
  3.    GraphicEditor := TGraphicEditor.Create(Self);
  4.    with GraphicEditor do
  5.    begin
  6.       Parent := GraphicalScrollBox;
  7.      Align := alCustom;
  8.      Anchors := [akTop, akLeft];
  9.      Top := 0;
  10.      Left := 0;
  11.      Visible := true;
  12.       Width := 4000;
  13.       Height := 4000;
  14.    end;
  15. end;
Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: spassigl on March 09, 2021, 06:34:52 pm
Well I had tried that as the first thing a couple of days ago, just to see if forcing a wider size would show the scrollbars.
No luck.

I'm starting to believe the problem is because the scrollbox is in a tabsheet?
Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: korba812 on March 09, 2021, 06:44:41 pm
Did you notice "Anchors" in my example?
Code: Pascal  [Select][+][-]
  1. Anchors := [akTop, akLeft];
Title: Re: Scrollbox horizontal scrollbars now showing up
Post by: spassigl on March 09, 2021, 06:53:40 pm
Shoot - that was the issue! Never thought about the anchors as an issue.

Thanks a bunch!
TinyPortal © 2005-2018