Home All Groups Group Topic Archive Search About

Get PictureBox with x height returned size of previously loaded image

Author
12 Jan 2006 5:16 PM
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?

Author
12 Jan 2006 6:46 PM
Scott Swigart
I haven't tested this, but what if you do "Application.DoEvents" after
setting the ImageLocation?  Then does it return the correct size?

Show quoteHide quote
"te***@yahoo.com" wrote:

> 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?
>
>
Author
13 Jan 2006 12:14 PM
Carlos J. Quintero [VB MVP]
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


<te***@yahoo.com> escribió en el mensaje
Show quoteHide quote
news:1137086164.777883.209110@g49g2000cwa.googlegroups.com...
> 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?
>
Author
18 Jan 2006 4:58 PM
tedqn
thanks guys but I figured it out. I put the code in
PictureBox.onLoadComplete event .. that's when the new stuff are
dupdated.