Recent

Author Topic: Behaviour of Scrollbars in TScrollbox for AutoScroll:= False;  (Read 4713 times)

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
There are some cases where I would like to have a TScrollbox with only a vertical scrollbar and this scrollbar should be always there, even if there is nothing to scroll (representation like a disabled TScrollbar). In TMemo and TStringGrid this behaviour can be achieved by setting
ScrollBars:= ssVertical.

It seems it is not possible to do this with TScrollbox.
If I set AutoScroll to false then the existence of Scrollbars depends on the fact if scrolling was needed while design time (Controls placed inside need more space). For me a strange behaviour. I would expect the existence of the scrollbars only (user)defined by HorzScrollBar.Visible and VertScrollBar.Visible.

Do I miss something? Is there a further setting to accomplish such a behaviour? Or is it just not possible with TScrollbox?

Why I need it: When the Scrollbars are dynamically shown and hidden, then the Clientwidth changes accordingly, which might require replacement of child controls. In some cases this is very nasty for both me as programmer and in a visual way for the user.

Thanks for Your Help!

System: Win7/64
Lazarus 1.6
FPC 3.0.0

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Behaviour of Scrollbars in TScrollbox for AutoScroll:= False;
« Reply #1 on: May 28, 2016, 07:27:39 pm »
I still don't know if its possible to use the TScrollbox in my intended way. But I found a workaround by placing a dummy TScrollbar (enabled:=false) on the correct possition and setting it to visible when autoscroll hides the scrollbar. This is determined by comparing the logical size with the client size:
Code: Pascal  [Select][+][-]
  1. LogRect:= GetLogicalClientRect;
  2. if LogRect.Bottom > Clientheight
  3.   then DummyScrollbar.Visible:= false
  4.   else DummyScrollbar.Visible:= true;

If the width is not set in the beginning it will have the standard width which is the same as in the tScrollbox (behaviour tested with Win7).

scribly

  • Jr. Member
  • **
  • Posts: 80
Re: Behaviour of Scrollbars in TScrollbox for AutoScroll:= False;
« Reply #2 on: April 06, 2017, 03:01:23 pm »
Is there really no other solution than using a dummy scrollbar ?

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: Behaviour of Scrollbars in TScrollbox for AutoScroll:= False;
« Reply #3 on: April 06, 2017, 06:48:14 pm »
If you really want
Code: Pascal  [Select][+][-]
  1. type
  2.   TAlwaysVisibleControlScrollBar = class(TControlScrollBar)
  3.   protected
  4.     function ScrollBarShouldBeVisible: Boolean; override;
  5.   end;
  6.  
  7. function TAlwaysVisibleControlScrollBar.ScrollBarShouldBeVisible: Boolean;
  8. begin
  9.   Result := Visible;
  10. end;
  11.  
  12. procedure ChangeClassForInstance(Instance: TObject; NewClass: TClass);
  13. begin
  14.   TClass(Pointer(Instance)^) := NewClass;
  15. end;
  16.  
  17. procedure TForm1.FormCreate(Sender: TObject);
  18. begin
  19.   ChangeClassForInstance(ScrollBox1.VertScrollBar, TAlwaysVisibleControlScrollBar);
  20. end;

scribly

  • Jr. Member
  • **
  • Posts: 80
Re: Behaviour of Scrollbars in TScrollbox for AutoScroll:= False;
« Reply #4 on: April 06, 2017, 10:45:09 pm »
interesting. thanks

 

TinyPortal © 2005-2018