Get PictureBox with x height returned size of previously loaded image

  • Thread starter Thread starter tedqn
  • Start date Start date
T

tedqn

I'm using VS 2005.
When user selects a image from the FileListBox, the code is


PictureBox.ImageLocation = sFullPath


PictureBox is set to AutoSize. When the newly loaded image is smaller
than the panel size, I want to center it within the panel by
calculating and move the box to a location other than (0,0). The
problem is that when retrieving the current box size
(PictureBox.Width/Height), it returns the previously auto sized
dimensions (base on the previously loaded image). Seems like I need to
run a "wait" function to wait for the new image to be fully loaded AND
the picbox's done auto sizing to get the correct size. How do I do
that?
 
I haven't tested this, but what if you do "Application.DoEvents" after
setting the ImageLocation? Then does it return the correct size?
 
Could you try to retrieve the image file into a System.Drawing.Image, get
its Height and Width, center the PictureBox and then set PictureBox.Image
property rather than ImageLocation?

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
thanks guys but I figured it out. I put the code in
PictureBox.onLoadComplete event .. that's when the new stuff are
dupdated.
 

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