In OnLoad
override method. there's base.OnLoad()
Should it called first or call it last after all custom code goes there?
protected override void OnLoad(EventArgs e) { // COde here? base.OnLoad(e); // or Code Here? }
Also many questions asking about Constructor vs Load event for User Controls in WinForms. Problem here that ParentForm not accessible in Constructor. and also all custom properties not accessible in constructor it all return null. but after Form_Load it readed. So why many suppose to use constructor? and other suppose to be it must all inside Load event. But as we know that Load event maybe manipulating any form variables makes a Refresh control multiple-times. which mean more slowly. Is there any overcome to that so constructor can forcibly access all properties and ParentForm
property.
Related Questions (It discuss it generally, What about Properties, ParentForm, etc) :
What setup code should go in Form Constructors versus Form Load event?
public partial class UserControl2 : UserControl { public UserControl2() { InitializeComponent(); var obj = FindForm(); // null var obj2 = ParentForm; // null var xx = helper; // null } [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] public string helper { get; set; } private void UserControl2_Load(object sender, EventArgs e) { var obj = FindForm(); // OK var obj2 = ParentForm; // OK var xx = helper; // OK } }
https://stackoverflow.com/questions/66947801/should-override-onload-and-call-base-load-before-load-event-or-after-in-user April 05, 2021 at 11:06AM
没有评论:
发表评论