Change the location of an object programmatically

前端 未结 6 875
南笙
南笙 2020-12-01 12:19

I\'ve tried the following code:

 this.balancePanel.Location.X = this.optionsPanel.Location.X;

to change the location of a panel that I mad

6条回答
  •  死守一世寂寞
    2020-12-01 12:44

    Use either:

    balancePanel.Left = optionsPanel.Location.X;
    

    or

    balancePanel.Location = new Point(optionsPanel.Location.X, balancePanel.Location.Y);
    

    See the documentation of Location:

    Because the Point class is a value type (Structure in Visual Basic, struct in Visual C#), it is returned by value, meaning accessing the property returns a copy of the upper-left point of the control. So, adjusting the X or Y properties of the Point returned from this property will not affect the Left, Right, Top, or Bottom property values of the control. To adjust these properties set each property value individually, or set the Location property with a new Point.

提交回复
热议问题