Reputation: 492
What are all the requirements to make a vertical scrollbar to show up? It seems very random.
I tried:
HorzScrollBar.Range := 10000; // set the range to an higher number
VertScrollBar.Range := 10000; // set the range to an higher number
ShowScrollBar(Handle, SB_BOTH, True);
In combination with adjusting ranges in object inspector as well as AutoScroll on/off, client height (of the form). I think I had all combinations possible in the past hour. It seems like it doesn't matter what I do, the scrollbar is not coming back anymore - where it first showed up when I randomly re-adjusted some settings (to the same settings?).
What I am trying to accomplish: when I press a button the form shows up and should show on the right of the screen, with the following:
Form1.Height := Screen.Height - 40;
Form1.Left := Screen.Width - 423;
Form1.Show;
The form is an options menu, where all the options fit perfectly on the screen I am using now. However, I made a panel that will become longer (more height) and push all other options down when a certain option is clicked. So THEN is when I need that scrollbar, as settings start falling off the screen.
Ideally it would only show up when those options where clicked and disappear when it is no longer necessary, but somehow it is not showing up at all - it doesn't matter what sizes or ranges I give the form.
What other option I am forgetting to set/what other dependents AutoScroll or just VerticalScrollbar have in order to show up when needed?
With ShowMessage function I have some more information. I created a button which performed the following:
procedure TfrmInstellingenMenu.Button1Click(Sender: TObject);
begin
VertScrollBar.Visible := true;
ShowMessage('Visible? ' + BoolToStr(VertScrollBar.IsScrollBarVisible));
//returns "Visible? -1". -1 is TRUE*, so yes (*tnx Ken)
ShowMessage('Autoscroll turned on? ' + BoolToStr(AutoScroll));
//returns "Autoscroll turned on? 0". 0 is False, so no
ShowMessage('Range=' + IntToStr(VertScrollBar.Range));
//returns "Range=8000".
end;
So although the VertScrollbar is turned on, AutoScroll (because of that) is automatically turned off plus the range is by far enough, why is it still hiding?
Edit2: Some more details: It is a VCL form, borderstyle is set to bsSizable. In the form there are basically only 2 panels of the same size. They have both constrained sizes and are aligned to left and right at start. A button aligns them to Top and to Bottom. When I set the button to set them both to align to Top, it does not matter what I set the form Height anymore (probably cause of the constraints of the two panels). It becomes too high for my computer screen though and a part of the form disappears off the screen. When I set one to align to top and the other to Bottom the whole form is on the screen, but the two panels overlap each other. Ah, and offcourse still no scrollbar.
Upvotes: 0
Views: 7866
Reputation: 21033
AutoScroll on
Setting Autoscroll = true
the scrollbar appears when the extents of the components on the form exceed the forms client size, if
bsSizeable
(default) or bsSizeToolWin
. VertScrollBar.Visible = false
Note! Changing border style in the IDE, and setting Autoscroll = true
, brings up the scrollbar for any border style, but only in the IDE. This has possibly confused you.
AutoScroll off
Setting VertScrollBar.Range
bigger than the client height of the form, brings up the scrollbar, regardless of BorderStyle
and regardless of Autoscroll
setting. In this case the visibility can be controlled with VertScrollBar.Visible
as needed.
You did not say which border style you want to use, but if it is one of those that hides the scrollbar, you can also consider placing your controls on a Scrollbox
with Align = alClient
.
Edit after edit2 in question:
Your "Edit2" changed the context but I offer you to consider the following test I made with a form, two panels and a button. To prevent the panels from overlapping (or leave a gap) in this context, you should set both panels to the same Align
. After changing Align
(for horizontal/vertical) simply reset the forms height to what it should be. Explained after the code below.
Added following field to the form:
private
Horizontal: boolean;
Constraints of Panel1
and Panel2
are set to 100, 150, 100, 150 (order as in OI)
Property Align
of both panels is set to alTop
. Form resizes to enclose the two panels.
Property Form5.AutoScroll
is set to True
and constraints of Form5
are set to 180, 180, 0, 0. Note how the scrollbar is visible, growing the width of the form to make room.
Button is placed on Panel1
and OnClick
looks like this:
procedure TForm5.Button1Click(Sender: TObject);
begin
Horizontal := not Horizontal;
if Horizontal then
begin
Panel2.Align := alLeft;
Panel1.Align := alLeft;
end
else
begin
Panel1.Align := alTop;
Panel2.Align := alTop;
Constraints.MaxHeight := 180; // set size of form back to what it should be
end;
end;
The reason for resetting the forms height, is that during calculation of extents, the forms constraints are not respected. Dunno if as designed or not, but is anyway why your form floats over. Subsequently, setting the forms constraints at design time is not really needed.
Upvotes: 3