Willy
Willy

Reputation: 10638

Handle event or something just before code for Control.ResumeLayout is executed

I have a System.Windows.Forms.UserControl which performs a this.ResumeLayout(false) at the end of the method InitializeComponent.

I would like to know if there is any way or event to handle just before the code for the ResumeLayout is executed.

I need to get the value for the property this.AutoScaleFactor just before ResumeLayout is executed. If that possible? If so, how.

It is so difficult to get around this because the code in InitializeComponent method is automatically generated by Visual Studio and ResumeLayout is being put there automatically as the last líne of the InitializeComponent. So I am also wondering if it is possible to tell Visual Studio to not add ResumeLayout(false) at the end of this method so I can call it manually later outside the InitializeComponent just after I get the scaling factor through this.AutoScaleFactor. For example in the constructor of the UserControl do:

InitializeComponent();
var scaleFactor = this.AutoScaleFactor;
this.ResumeLayout(false);

Upvotes: 0

Views: 146

Answers (1)

Charlieface
Charlieface

Reputation: 71119

You can just call SuspendLayout before InitializeComponent, then call ResumeLayout afterwards. As noted in Do Control.SuspendLayout and Control.ResumeLayout keep count?, the control keeps count of how many times you call it and does not redo the layout until you call ResumeLayout enough times.

this.SuspendLayout();
InitializeComponent();
var scaleFactor = this.AutoScaleFactor;
this.ResumeLayout(false);

Upvotes: 1

Related Questions