all groups > dotnet windows forms designtime > march 2006 >
You're in the

dotnet windows forms designtime

group:

Why Form Designer does not generate properties for controls (only fields)?


Why Form Designer does not generate properties for controls (only fields)? tomj NO[at]SPAM softhome.net
3/28/2006 3:20:19 AM
dotnet windows forms designtime:
Form Designer generates only fields for controls.

Form1.Designer.cs:
....
private Button closeButton;
....

Disadvantages:
- if I want to make closeButton protected or public I need to manually
write property(because making field protected or public is not
recommended)
- event handlers for controls does not follow method naming convention
(should use Pascal Casing)
Ex: private void closeButton_Click(object sender, EventArgs e)
- ....


As for me I expect Form Designer to generate something like this:
....
private Button closeButton;

private Button CloseButton
{
get { return closeButton }
}
....

Why not?
Re: Why Form Designer does not generate properties for controls (only fields)? Kevin Spencer
3/28/2006 7:58:56 AM
[quoted text, click to view]

Making a Control protected or public by default is a bad idea. The Control
is generally only used by the Form itself. Properties are used to expose
members to other classes. The members are made private fields by default
because that is the most likely and safest thing to do when writing your
code for you. Anything else is poor use of encapsulation.

[quoted text, click to view]

An Event Handler is not specifically a Method. It is used as a delegate. As
for how it *should* be cased, that is purely arbitrary. Microsoft has
long-established conventions for code that are employed across the board in
uniform fashion across the enterprise. You may find the following section of
the MSDN Library useful:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnetframeworkdesignguidelines.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

[quoted text, click to view]

Re: Why Form Designer does not generate properties for controls (only fields)? tomj NO[at]SPAM softhome.net
3/30/2006 1:31:57 AM
[quoted text, click to view]

And what about forms inheritance?

Some controls in base form should be protected.

What you propose to do?
AddThis Social Bookmark Button