In Visual Studio, while working on Windows Forms Applications a certain option can be found in the Form Design View. I'm talking about the GenerateMember
option (under the Design
section of the Properties Window).
The description of this option is the following:
Indicates if a member variable will be generated for this component.
So, if I create a text box tb1
using the Form Dessigner into my Form f1
and I set this option to false
, then I cannot access the control within the code (neither f1.tb1
nor tb1
exists).
There should be a good reason for doing that, but I don't know what this reason could be, that's why I'm asking:
Design
> GenerateMember
option?GenerateMember
to false instead of letting it to have the default value (true)?Thank you.
When GenerateMember
is set to false
, instead of having a lot of private fields scoped to the Form class instance, they are created scoped to the InitializeComponent()
method - meaning you will no longer have this.btnOk
or this.btnCancel
accessible to anything within your form.
I've figured it is, for the most part, just a personal preference. By specifying which controls you want directly visible as private fields to the rest of your form class, you can avoid getting lost in a sea of unused fields when modifying your code.
Other than that, there is no real functional difference. You could still access the controls via: this.Controls
collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With