When running the code, the form displays normally, but the designer cannot display it and prompts an error that "txtbox" is not declared or assigned a value.
The Windows Forms Designer deserializes and loads the first class in the file to create the component and set its properties based on the InitializeComponents
method and the component declaration found in the .cs file.
In this example, the declaration of "txtbox" is in the first file, but the designer cannot serialize and load it because it is in a partial class in the first file.
To fix this problem, just move the declaration of "txtbox" from the first file to a local class in the second file. This allows the designer to access and load the form when it is initialized.
InitializeComponents
are not. The above is the detailed content of Why Can't I See My C# Windows Form Designer When 'txtbox' is Undeclared?. For more information, please follow other related articles on the PHP Chinese website!