Reputation: 139
in Microsoft windows visual c# windows form application I keep getting this error message.
Error 1 Property or indexer 'System.Windows.Forms.Control.Bottom' cannot be assigned to -- it is read only
I can move the image with a int Control.Left or a Top but not a Bottom or Right what wrong with it
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Bottom += 1;
}
Upvotes: 1
Views: 985
Reputation: 1
[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
Upvotes: 0
Reputation: 236248
As error says, you cannot assign Bottom property - its calculated based on control size and location:
public int Bottom
{
get { return this.y + this.height; }
}
And its for reading only. On the other hand, Left and Top will change bounds of control by changing it's x
or y
position:
public int Left
{
get { return this.x; }
set
{
SetBounds(value, this.y, this.width, this.height, BoundsSpecified.X);
}
}
Upvotes: 0
Reputation: 294
Bottom property is read only (as Right is). You can however manipulate it's value indirectly by changing values of Top or Size properties.
Upvotes: 1
Reputation: 166406
The value of this property is equal to the sum of the Top property value, and the Height property value.
The Bottom property is a read-only property. You can manipulate this property value by changing the value of the Top or Height properties or calling the SetBounds, SetBoundsCore, UpdateBounds, or SetClientSizeCore methods.
Upvotes: 1
Reputation: 19111
Presumably your picture is a square, meaning you should easily be able to calculate the required Top
and Left
positions from the Bottom
and Right
you would like, together with the height and width of the picture.
Do that instead, and just use Top
and Left
.
Upvotes: 0