ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Graphics question on Excel VBA UserForm (https://www.excelbanter.com/excel-programming/334728-graphics-question-excel-vba-userform.html)

Jens Meier

Graphics question on Excel VBA UserForm
 
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

Ivan F Moala[_63_]

Graphics question on Excel VBA UserForm
 

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.


--
Ivan F Moala


------------------------------------------------------------------------
Ivan F Moala's Profile: http://www.excelforum.com/member.php...fo&userid=1954
View this thread: http://www.excelforum.com/showthread...hreadid=387744


keepITcool

Graphics question on Excel VBA UserForm
 

.... 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 :

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


Jens Meier

Graphics question on Excel VBA UserForm
 
keepITcool schrieb:
... 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

keepITcool

Graphics question on Excel VBA UserForm
 
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 :

keepITcool schrieb:
... 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


Jens Meier

Graphics question on Excel VBA UserForm
 
keepITcool schrieb:
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

keepITcool

Graphics question on Excel VBA UserForm
 

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 :

keepITcool schrieb:
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


Jens Meier

Graphics question on Excel VBA UserForm
 
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

Jens Meier

Graphics question on Excel VBA UserForm
 
Jens Meier schrieb:
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

keepITcool

Graphics question on Excel VBA UserForm
 
glad to have helped :)

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


Jens Meier wrote :

Jens Meier schrieb:
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



All times are GMT +1. The time now is 08:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com