当我试图移动我的照片.Bottom继续得到错误,但我可以移动它.Left和.Top

时间:2013-12-09 07:39:06

标签: c# visual-studio-2013

在Microsoft Windows visual c#windows form应用程序中我不断收到此错误消息。

错误1无法将属性或索引器'System.Windows.Forms.Control.Bottom'分配给 - 它是只读的

我可以使用int Control.Left或Top移动图像但不是底部或右边有什么问题

private void button1_Click(object sender, EventArgs e)
        {
            pictureBox1.Bottom += 1;

        }

5 个答案:

答案 0 :(得分:1)

来自Control.Bottom Property

  

此属性的值等于Top属性的总和   value和Height属性值。

     

Bottom属性是只读属性。您可以对此进行操作   通过更改Top或Height属性的值来设置属性值   或调用SetBounds,SetBoundsCore,UpdateBounds或   SetClientSizeCore方法。

答案 1 :(得分:1)

底部属性是只读的(正确的是)。 但是,您可以通过更改“顶部”或“大小”属性的值来间接操纵它的值。

答案 2 :(得分:0)

如错误所示,您无法指定Bottom属性 - 根据控件大小和位置计算:

public int Bottom
{
    get { return this.y + this.height; }
}

它只供阅读。另一方面,LeftTop会更改控件的xy位置,从而改变控制范围:

public int Left
{
    get { return this.x; }
    set
    {
        SetBounds(value, this.y, this.width, this.height, BoundsSpecified.X);
    }
}

答案 3 :(得分:0)

据推测,您的照片是正方形,这意味着您应该可以轻松地计算出您想要的TopLeft所需的BottomRight位置与图片的高度和宽度。

请改为使用TopLeft

答案 4 :(得分:0)

    [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
相关问题