How can I change the properties of a control after a resource file has been applied?

I need to add a scroll bar for a component when the user changes his font size to 125% or 150%. To do this, I added a method to the component that 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 have a scroll bar.

The above method will be launched upon initialization of such controllers:

 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 activated when added to the controls, after which the resource will be applied. The component that I do not want to change relates to ucASNSearchCriteria in the above code.

Now I want to set the AutoScroll property 'ucASNSearchCriteria' to false after the resource has been applied. I have little information about the rendering process of C # ui controls. Is it possible to dynamically change properties after application?

+5
source share
1 answer

I would create a derivative control of the required type and add the AllowAutoScroll property or something similar with the default value true .

With this, you can easily change this property in the WinForms constructor and respond to this property as you resize.

So, the designer will add this line of code for you if you change it to non-standard ( false ):

 this.ucASNSearchCriteria.AllowAutoScroll = false; 

... and you can respond to this new property as follows:

 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); }); } } } 
+2
source

All Articles