Home > Mobile >  C# WinForms - Instance of Form Not Showing Label Values Set in Designer
C# WinForms - Instance of Form Not Showing Label Values Set in Designer

Time:01-24

I have a legacy single form app and I wanted to add a few other forms to it.

So I add a form, an aboutBox to start off with, in the designer of the form I set the text property of various labels to what I want and I can see them change on the form design view. I then instantiate and display the form inside the click function of a button on the main form:

AboutBox1 aboutBox = new AboutBox1();
aboutBox.Show();

But then at run time the form appears with default placeholder text in all the labels - it completely ignores what I set in the designer?

CodePudding user response:

Did you try to set your content from code instead of from designer? About box shows default Application info from app manifest, on runing. Maybe it's a good way to create similar window by "Form" template.

In constructor default window AboutBox you can see this:

this.Text = String.Format("Information about {0}", AssemblyTitle);
this.labelProductName.Text = AssemblyProduct;
this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion);
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
this.textBoxDescription.Text = AssemblyDescription;

This some lines is responsible to override your data after lauch. Change it and try again.

  •  Tags:  
  • Related