以编程方式更改对象的位置 [英] Change the location of an object programmatically
本文介绍了以编程方式更改对象的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了以下代码:
this.balancePanel.Location.X = this.optionsPanel.Location.X;
更改程序运行时在设计模式下制作的面板的位置,但返回错误:
to change the location of a panel that I made in design mode while the program is running but it returns an error:
无法修改'System.Windows.Forms.Control.Location'的返回值,因为它不是变量。 / p>
Cannot modify the return value of 'System.Windows.Forms.Control.Location' because it is not a variable.
那我该怎么办?
推荐答案
位置
属性的类型为 Point
这是一个结构。
The Location
property has type Point
which is a struct.
不要尝试修改现有的 Point
,而是要分配一个新的 Point
对象:
Instead of trying to modify the existing Point
, try assigning a new Point
object:
this.balancePanel.Location = new Point(
this.optionsPanel.Location.X,
this.balancePanel.Location.Y
);
这篇关于以编程方式更改对象的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文