How to change size of PictureBox from code ?

  • Thread starter Thread starter vertigo
  • Start date Start date
V

vertigo

Hello
When i tried to:
pictureBox.Size.Width = 100;

i receive:
DscFile.cs(58): Cannot modify the return value of
'System.Windows.Forms.Control.Size' because it is not a variable

Why ?
How can i change it's size ?

Thanx
Michal
 
Michal,

Since the Size type is a value type, a copy of it is returned when you
access a property which exposes it. You will have to set the type yourself,
like so:

// Get the size in a temp variable.
Size tempSize = pictureBox.Size;

// Set the Width.
tempSize.Width = 100;

// Set the size back.
pictureBox.Size = tempSize;

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top