The ScrollableControl class has 2 protected boolean properties: HScroll and VScroll.
As the document says:
Gets or sets a value indicating whether the horizontal scroll bar is visible.
And
AutoScroll maintains the visibility of the scrollbars automatically. Therefore, setting the HScroll or VScroll properties to true have no effect when AutoScroll is enabled.
So I use them like this, but the scrollbar isn't showed:
class MyScrollableControl : ScrollableControl {
public MyScrollableControl() {
this.AutoScroll = false;
this.HScroll = true;
}
}
If I use the following code, it works:
this.HorizontalScroll.Visible = true;
When I put them torgether, the scrollbar is still invisible, and the values of HScroll and HorizontalScroll.Visible keep False.
this.AutoScroll = false;
this.HScroll = true;
this.HorizontalScroll.Visible = true;
So what is the real use of HScroll and VScroll ?
Update
My code and test
HScroll
property does not affect scroll visibility directly, but it prevent Scroll to be hidden with HorizontalScroll.Visible
value
In case when HorizontalScroll.Visible
is set to true
than HScroll
will also get a value true
(see 2nd line in the table)
In case when AutoScroll
is set to true HorizontalScroll.Visible
always stays true
and HScroll
doesnot have any influense (see last 2 lines)
Make an app with Control that contains 3 buttons with next handler code, and play with it to see what exactly happening there:
private void button1_Click(object sender, EventArgs e)
{
AutoScroll = !AutoScroll;
SetValues();
}
private void button3_Click(object sender, EventArgs e)
{
HScroll = !HScroll;
SetValues();
}
private void SetValues()
{
button1.Text = $"Auto: {(AutoScroll ? "On" : "Off")}";
button3.Text = $"HScroll: {(HScroll ? "On" : "Off")}";
button2.Text = $"Visible: {(HorizontalScroll.Visible ? "On" : "Off")}";
}
private void button2_Click(object sender, EventArgs e)
{
HorizontalScroll.Visible = !HorizontalScroll.Visible;
SetValues();
}
false
)To Manually show Scroll set HorizontalScroll.Visible
to true
To Manually hide Scroll set HScroll
to false
and than HorizontalScroll.Visible
to false
true
)HorizontalScroll.Visible
is always true
and cannot be changed
HScroll
doesnot affects anything
So what is the real use of HScroll and VScroll ?
You set them to true when you have the intention of showing the scrollbars. But that is not enough, you also have to state what they should display. A scrollbar needs to know the thumb size, minimum and maximum position and current position.
You are doing battle with the internal ApplyScrollbarChanges() method. One thing it does is hide the scrollbars, even if HScroll or VScroll is set to true, if it does not have sufficient info to configure the bars. The code of the method is too large to fit here, in a nutshell it derives this info from:
Item 2 is an attractive customization angle, but they made the LayoutEngine class internal so you can't derive your own. Item 3 is not fundamentally different from what AutoLayout = true already does. It does work however, just add a control in the constructor, override OnClientSizeChanged() to call AdjustFormScrollbars(true) and you'll now see the scrollbar.
Which leaves item 1 to control the scrollbars. The property setter looks like this. Yup, it sneakily sets the AutoScroll property back to true :)
Simply set the AutoScrollMinSize property to control the scrollbars.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With