C# 当我尝试使用.Bottom移动图片时,不断出现错误,但我可以使用.Left和.Top移动图片
在Microsoft windows visual c#windows窗体应用程序中,我不断收到此错误消息 错误1属性或索引器“System.Windows.Forms.Control.Bottom”无法分配给--它是只读的 我可以用int控件移动图像。左或上,但不是下或右。怎么了C# 当我尝试使用.Bottom移动图片时,不断出现错误,但我可以使用.Left和.Top移动图片,c#,visual-studio-2013,C#,Visual Studio 2013,在Microsoft windows visual c#windows窗体应用程序中,我不断收到此错误消息 错误1属性或索引器“System.Windows.Forms.Control.Bottom”无法分配给--它是只读的 我可以用int控件移动图像。左或上,但不是下或右。怎么了 private void button1_Click(object sender, EventArgs e) { pictureBox1.Bottom += 1;
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Bottom += 1;
}
正如错误所说,您无法分配属性-它是根据控件大小和位置计算的:
public int Bottom
{
get { return this.y + this.height; }
}
它只供阅读。另一方面,和将通过更改其x
或y
位置来更改控制范围:
public int Left
{
get { return this.x; }
set
{
SetBounds(value, this.y, this.width, this.height, BoundsSpecified.X);
}
}
假设您的图片是正方形,这意味着您应该能够轻松地计算所需的
顶部
和左侧
位置,以及图片的高度和宽度
改为这样做,只需从中使用Top
和Left
此属性的值等于Top属性的和
值和“高度”特性值
底部属性是只读属性。您可以对其进行操作
通过更改“顶部”或“高度”特性的值来获取特性值
或调用SetBounds、SetBoundsCore、UpdateBounds或
SetClientSizeCore方法
底部属性为只读(与右侧相同)。
但是,您可以通过更改“顶部”或“大小”属性的值来间接操纵其值。您应该使用“顶部”和“左侧”属性来重新定位picturebox
[Read my Blog Techhowdy][1]
// For right
pictureBox1.Top = ((Control)sender).Top;
pictureBox1.Height = ((Control)sender).Height;
// For bottom
pictureBox1.Left = ((Control)sender).Left;
pictureBox1.Width= ((Control)sender).Width;
// For top
pictureBox1.Top= ((Control)sender).Top;
pictureBox1.Width = ((Control)sender).Width;
// Casting it to Control will solve your problem - use Left as it can be manupilated
[1]: http://techhowdy.com