elucid8
elucid8

Reputation: 1422

Why can't I set the margin of a FlowLayoutPanel programmatically?

I'm trying to set the margin of a FlowPanel programmatically in C#, however it tells me that I can't set it because it isn't a variable.

Here it is telling me that the property gets or sets the space between controls.

Normal property?

But, once I try to set the property, it tells me that it isn't a variable and the project won't compile.

Am I crazy, or what?

So, what is happening here? Is this property declared in a weird way behind the scenes? Is it a problem with Visual Studio? I'm at a loss.

Upvotes: 1

Views: 1829

Answers (1)

user1693593
user1693593

Reputation:

You must assign a new value:

flowLayoutPanel2.margin = new Padding(5);

Update: Although there is no such remark for Padding there is an explaination for Point which also is a structure and why it need to be set as a new Padding (Point in the following description):

Point [Padding] is a structure, which means that it is a value type. If you access a property in Point, a copy of the property is returned. Therefore, changing the X or Y properties of the Point returned from the Location property will not affect the Left, Right, Top, or Bottom property values of the Form. To adjust these properties, set each property value individually, or set the Location property with a new Point.

Source:
http://msdn.microsoft.com/en-us/library/ms159414.aspx

Public Structure Padding

Padding:
http://msdn.microsoft.com/en-us/library/system.windows.forms.padding.aspx

Upvotes: 2

Related Questions