Tim Gradwell
Tim Gradwell

Reputation: 2412

How do I stop the designer from filling in my properties with null values?

When I add a control to a form, visual studio assigns various of the properties of that form a value of null in the auto-generated designer code.

I don't want the designer to make the redundant assignment (the value is already null).

Can anyone tell me how to prevent it?


example

MyControl has property

public SomeClass MyProperty
{
   get { return m_MyValue; }
   set { m_MyValue = value; }
}

designer then autogenerates the following:

myControl1.MyProperty = null;

Upvotes: 2

Views: 345

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283773

[DefaultValue(null)]

Upvotes: 4

Robert Harvey
Robert Harvey

Reputation: 180868

myControl1.MyProperty = null; and the setting in the designer are the same thing.

If you change the value for the setting in the line of code, then go to the designer, and you will see that the value has changed in the designer also. Similarly, if you change the value in the designer, the value in the code will change.

Upvotes: 0

Related Questions