I can set Maximum and Minimum Size height and width values for a DGV at design time but not in code. This won’t compile, as “Cannot modify the return value of ‘System.Windows.Forms.Control.MaximumSize’ because it is not a variable”:
dataGridViewPlatypi.MaximumSize.Height = dataGridViewPlatypi.Size.Height;
dataGridViewPlatypi.MinimumSize.Height = dataGridViewPlatypi.Size.Height;
dataGridViewPlatypi.MaximumSize.Width = dataGridViewPlatypi.Size.Width;
dataGridViewPlatypi.MinimumSize.Width = dataGridViewPlatypi.Size.Width;
If MaximumSize is not a variable, why can I modify it in the IDE?
Read the error message more carefully:
Control.MaximumSizeis of the typeSize, which is a value type. The property returns a copy of aSizeobject and you then proceed to attempt to modify its properties. Even if you could modify them it would accomplish nothing as you would only be mutating a copy.You need to set the property to an entirely new value, not just change the properties of a copy.