I need to add a scroll bar for a component when a user changes their font size to 125% or 150%. To do this I added a method in the component, which sets the AutoScroll property to true.
protected override void OnSizeChanged(EventArgs e)
{
if (SystemFonts.DefaultFont.Size < 8)
{
this.AutoScroll = true;
}
if (this.Handle != null)
{
this.BeginInvoke((MethodInvoker) delegate
{
base.OnSizeChanged(e);
});
}
}
This works well, but one of the components should not get a scrollbar.
The above method will be triggered when initializing the controllers like this:
this.ultraExpandableGroupBoxPanel1.Controls.Add(this.pnlViewMode);
this.ultraExpandableGroupBoxPanel1.Controls.Add(this.ucASNSearchCriteria);
resources.ApplyResources(this.ultraExpandableGroupBoxPanel1, "ultraExpandableGroupBoxPanel1");
this.ultraExpandableGroupBoxPanel1.Name = "ultraExpandableGroupBoxPanel1";
The method will be triggered when adding into Controls and after this, the resource will be applied. The component which I don't want to change belongs to ucASNSearchCriteria
in above code.
Now I want to set the AutoScroll
property of 'ucASNSearchCriteria' to false after the resource has been applied. I have little knowledge about the rendering process of c# ui controls. Is it possible to dynamically change properties after applying?
I'd create a derived control of the desired type and add a property AllowAutoScroll
or anything like that with the default value true
.
With this, you can change that property in the WinForms designer easily and react on that property as the size gets changed.
So the designer will add this line of code for you if you change it to be non-default (false
):
this.ucASNSearchCriteria.AllowAutoScroll = false;
... and you can react on that new property like this:
protected override void OnSizeChanged(EventArgs e)
{
if (AllowAutoScroll)
{
if (SystemFonts.DefaultFont.Size < 8)
{
this.AutoScroll = true;
}
if (this.Handle != null)
{
this.BeginInvoke((MethodInvoker) delegate
{
base.OnSizeChanged(e);
});
}
}
}
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