Windows Forms Designer, Design Basis> GenerateMember

In Visual Studio, when working on Windows Forms applications, a specific option can be found in the Design Design view. I am talking about an option GenerateMember(in the section of Designthe properties window).

The description of this parameter is as follows:

Indicates whether a member variable will be created for this component.

So, if I create a text box using the Dessigner form in my form , and I set this option to , then I cannot access the control inside the code (neither , nor ). tb1 f1false f1.tb1 tb1

There must be a good reason for this, but I don’t know what this reason is, why I ask:

  • What is the meaning of the Design> option GenerateMember?
  • What can be achieved by setting this option to false, which cannot be achieved with it to true?
  • In what situations should I prefer to hide the control parameter GenerateMemberinstead of false, instead of letting it have a default value (true)?

Thanks.

+4
source share
1 answer

If a parameter is GenerateMemberset to a value falseinstead of a large number of private fields associated with an instance of the Form class, they are created with a method binding InitializeComponent()- this means that you will no longer have this.btnOkor will be this.btnCancelavailable for anything in your form.

, , , . , , .

, . : this.Controls .

+4

Source: https://habr.com/ru/post/1618609/


All Articles