Graphics question on Excel VBA UserForm

J

Jens Meier

Hello newsgroup,

I got to this group from the public German Excel group, where my
question could not be answered. I hope this is the correct place. :)

This is my situation:
I have an Excel UserForm where I display a low-resolution image. After a
user click on the image, I want the picture to "zoom in", i.e. I want to
replace the low-resolution image with a small portion of a
high-resolution image showing more details.

Any hints on how this can be achieved with some API function?

Thank you very much!
Jens
 
I

Ivan F Moala

Hi Jens

One way is to use a control that has a Zoom property AND acepts images
eg a Frame. Just load in your high def image and use the Frames Zoom
property.
If you have a number of pictures, then I would use an Image control to
store these.
 
K

keepITcool

.... api's not needed

but you'll need to put the image in a frame to get the "panning"
mechanism that forms.imagecontrol doesnt have.

you'll only load the large hires picture but control the size of the
imagecontrol. (sizemode must be set to zoom)


Could keep the scrollbars hidden and manipulate the scrolltop.left/ etc
with a few buttons.

Private Sub UserForm_Initialize()
With Me.Frame1
.ScrollBars = fmScrollBarsNone
.KeepScrollBarsVisible = fmScrollBarsNone
End With
With Me.Image1
.Top = 0
.Left = 0
.Height = Me.Frame1.InsideHeight
.Width = Me.Frame1.InsideWidth
.PictureSizeMode = fmPictureSizeModeZoom
End With
End Sub

Private Sub Image1_Click()
With Me.Frame1
If .ScrollBars = fmScrollBarsNone Then
.ScrollBars = fmScrollBarsBoth

Me.Image1.AutoSize = True
.ScrollHeight = Image1.Height
.ScrollWidth = Image1.Width
Else
.ScrollTop = 0
.ScrollLeft = 0
.ScrollWidth = .Width
.ScrollHeight = .Height
.ScrollBars = fmScrollBarsNone

Me.Image1.AutoSize = False
Me.Image1.Height = .InsideHeight
Me.Image1.Width = .InsideWidth
End If
End With
End Sub







--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jens Meier wrote :
 
J

Jens Meier

keepITcool said:
... api's not needed

but you'll need to put the image in a frame to get the "panning"
mechanism that forms.imagecontrol doesnt have.

you'll only load the large hires picture but control the size of the
imagecontrol. (sizemode must be set to zoom)

Could keep the scrollbars hidden and manipulate the scrolltop.left/ etc
with a few buttons.

Hi keepITcool,

thanks a lot for your reply. I guess this is a really helpful approach.
But unfortunately I was unable to fully understand what your code does.

Here is what I did: I created a UserForm with a Form and an Image object
inside the Form. Then I loaded a picture (the supposed low-resolution
image) into the Image. After showing the userform, the image filled the
whole frame, and on clicking the image, it resized to its original size
(no stretch).

At this point I got stuck. How can I reach that on clicking the image
the high-res image is loaded and zoomed/panned to the right spot?
Actually, only panning the high-res image would be enough.
I tried to play with the ScrollWidth/Height/Top/Left properties, but
could not see any effect on the behaviour of the userform.

As I think we got quite close to the thing (I've been searching for
quite a while now...), I would really appreciate further help!
Thank you,
Jens
 
K

keepITcool

as I said..

you load the hires picture (which initially is shown as a thumbnail.)

IF you want to actually swap hires and lores pictures
(reread from disk) you must include some code to do that.


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jens Meier wrote :
 
J

Jens Meier

keepITcool said:
as I said..

you load the hires picture (which initially is shown as a thumbnail.)

IF you want to actually swap hires and lores pictures
(reread from disk) you must include some code to do that.

OK,

that's clear to me - the high-res picture is shown as a thumbnail.

But on the event of clicking the image, how can I possibly pan it to be
centered on the mouseclick position?? And zoomed in?
I played around with ScrollWidth/Height/..., but got no results...

Thanks again,
Jens
 
K

keepITcool

remove the image_click replace with

Private Sub Image1_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
Dim f#
With Me.Frame1
If .ScrollBars = fmScrollBarsNone Then
.ScrollBars = fmScrollBarsBoth
Me.Image1.AutoSize = True
.ScrollHeight = Image1.Height
.ScrollWidth = Image1.Width

f = (Image1.Height / .Height)
.ScrollTop = (y - .Top) * f
.ScrollLeft = (x - .Left) * f

Else
.ScrollTop = 0
.ScrollLeft = 0
.ScrollWidth = .Width
.ScrollHeight = .Height
.ScrollBars = fmScrollBarsNone

Me.Image1.AutoSize = False
Me.Image1.Height = .InsideHeight
Me.Image1.Width = .InsideWidth
End If
End With
End Sub




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jens Meier wrote :
 
J

Jens Meier

keepITcool,

thanks a lot for your help.

I still have to do some testing, I am currently inserting your code into
my (far more complex) program.
But this seems to do what I was looking for!

Thank you again!
Jens
 
J

Jens Meier

Jens said:
thanks a lot for your help.

I still have to do some testing, I am currently inserting your code into
my (far more complex) program.
But this seems to do what I was looking for!

I've fully integrated the code into the existing program now, I've added
some additional features (such as panning the image, switching between
different resolution because Excel doesn't render large images well,
etc.) and it works perfectly!

So thank you again!
Jens
 

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

Top