Cannot modify expression because it is not a variable

后端 未结 5 780
情书的邮戳
情书的邮戳 2020-12-20 19:34

I\'m trying to get an UserControl (which has a grid on it) on a Windows Form to resize. The below code is what I have in the Form. The behavior I\'m getting is that the con

5条回答
  •  有刺的猬
    2020-12-20 20:15

    You can't directly change the Size.Width property on a UserControl, because the Size property is a value type, so changing its width would essentially be overwriting the entire Size property. Instead, controls in WinForms provide their own Width and Height properties, so this code should work:

    grdNameValueProperties.Width = this.Width - 8;
    grdNameValueProperties.Height = this.Height - 8;
    

    Having said that, I agree with @recursive's comment that you should probably just use the UserControl's Anchor property to make it "automatically" resize.

提交回复
热议问题