Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm displaying a picture on a Form and
using the zoom property to adjust the size. The problem is this resizes the picture but not the form. Is there a method to force the form to the same size as the picture. Or, can I display just the picture without a form? There is one command button in use on the form as well. Thanks - Kirk |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Kirk,
Why not use an image control with its Autosize property set to true, resize the form to the image, eg sFile = "c:\pictures\mypicture.jpg" Me.Image1.Picture = LoadPicture(sFile) With Me.Image1 ..AutoSize = True ' or set at design time ..Left = 0 ..Top = 0 Me.Width = .Width Me.Height = .Height End With You might also want to re position the form to centre in the monitor, or even re-scale if the image doesn't fit. So might need the GetSystemMetrics32 api to get the screen resolution. Regards, Peter T "kirkm" wrote in message ... I'm displaying a picture on a Form and using the zoom property to adjust the size. The problem is this resizes the picture but not the form. Is there a method to force the form to the same size as the picture. Or, can I display just the picture without a form? There is one command button in use on the form as well. Thanks - Kirk |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I forgot would need to increase the form's height by same as its title bar
height Private Declare Function GetSystemMetrics Lib "user32" _ (ByVal nIndex As Long) As Long Const SM_CYCAPTION = 4 CaptionHeight = GetSystemMetrics(SM_CYCAPTION) Other constants you might need to return dimensions from GetSystemMetrics Const SM_CXSCREEN = 0 ' screen pixel width Const SM_CYSCREEN = 1 '' screen pixel height Const SM_CYMENU = 15 taskbar height Const SM_CXFULLSCREEN = 16 Const SM_CYFULLSCREEN = 17 Then need to convert from pixels to points by multiplying by factor 0.75 (ie typically assuming not large system font). Also, this simplified method might trim the image slightly as borders are not taken into account. Regards, Peter T "Peter T" <peter_t@discussions wrote in message ... Hi Kirk, Why not use an image control with its Autosize property set to true, resize the form to the image, eg sFile = "c:\pictures\mypicture.jpg" Me.Image1.Picture = LoadPicture(sFile) With Me.Image1 .AutoSize = True ' or set at design time .Left = 0 .Top = 0 Me.Width = .Width Me.Height = .Height End With You might also want to re position the form to centre in the monitor, or even re-scale if the image doesn't fit. So might need the GetSystemMetrics32 api to get the screen resolution. Regards, Peter T "kirkm" wrote in message ... I'm displaying a picture on a Form and using the zoom property to adjust the size. The problem is this resizes the picture but not the form. Is there a method to force the form to the same size as the picture. Or, can I display just the picture without a form? There is one command button in use on the form as well. Thanks - Kirk |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Peter,
Thanks for the examples. I'm still playing around with them. I'm new to this. Cheers - Kirk On Tue, 17 Oct 2006 11:05:52 +0100, "Peter T" <peter_t@discussions wrote: I forgot would need to increase the form's height by same as its title bar height Private Declare Function GetSystemMetrics Lib "user32" _ (ByVal nIndex As Long) As Long Const SM_CYCAPTION = 4 CaptionHeight = GetSystemMetrics(SM_CYCAPTION) Other constants you might need to return dimensions from GetSystemMetrics Const SM_CXSCREEN = 0 ' screen pixel width Const SM_CYSCREEN = 1 '' screen pixel height Const SM_CYMENU = 15 taskbar height Const SM_CXFULLSCREEN = 16 Const SM_CYFULLSCREEN = 17 Then need to convert from pixels to points by multiplying by factor 0.75 (ie typically assuming not large system font). Also, this simplified method might trim the image slightly as borders are not taken into account. Regards, Peter T "Peter T" <peter_t@discussions wrote in message ... Hi Kirk, Why not use an image control with its Autosize property set to true, resize the form to the image, eg sFile = "c:\pictures\mypicture.jpg" Me.Image1.Picture = LoadPicture(sFile) With Me.Image1 .AutoSize = True ' or set at design time .Left = 0 .Top = 0 Me.Width = .Width Me.Height = .Height End With You might also want to re position the form to centre in the monitor, or even re-scale if the image doesn't fit. So might need the GetSystemMetrics32 api to get the screen resolution. Regards, Peter T "kirkm" wrote in message ... I'm displaying a picture on a Form and using the zoom property to adjust the size. The problem is this resizes the picture but not the form. Is there a method to force the form to the same size as the picture. Or, can I display just the picture without a form? There is one command button in use on the form as well. Thanks - Kirk |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Peter, I'm getting the same effect with the image control as the picture. When I zoom e.g. to 75 the image reduces, but the form stays the initial size. What I'm hoping to achieve is have the picture and form resize together. Zoom is good because it allows both smaller and larger resizing. Thanks - Kirk |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm not quite sure what you are trying to do, perhaps something like this -
Userform with image control named Image1 change the picture file name click on image to change zoom +/-25% Option Explicit Private Declare Function GetSystemMetrics Lib "user32" _ (ByVal nIndex As Long) As Long Const SM_CYCAPTION = 4 Dim mWd As Long, mHt As Long Dim mCapHt As Long Dim mInc As Long Dim mZm As Long Const cBDR_WD = 4 ' approx image border width Private Sub Image1_Click() If mZm 125 Then mInc = -1 If mZm < 50 Then mInc = 1 mZm = mZm + (25 * mInc) Me.Zoom = mZm Me.Width = Int(mWd * mZm / 100) + cBDR_WD Me.Height = Int(mHt * mZm / 100) + mCapHt Me.Caption = mZm & "%" End Sub Private Sub UserForm_Initialize() Dim sFile As String sFile = "c:\pictures\myPicture.jpg" ' ==CHANGE mCapHt = GetSystemMetrics(SM_CYCAPTION) With Me.Image1 .AutoSize = True .Left = 0 .Top = 0 .Picture = LoadPicture(sFile) mWd = .Width mHt = .Height End With Me.Top = 0 Me.Width = mWd + cBDR_WD Me.Height = mHt + mCapHt mInc = -1 mZm = 100 End Sub Regards, Peter T "kirkm" wrote in message ... Peter, I'm getting the same effect with the image control as the picture. When I zoom e.g. to 75 the image reduces, but the form stays the initial size. What I'm hoping to achieve is have the picture and form resize together. Zoom is good because it allows both smaller and larger resizing. Thanks - Kirk |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Thu, 19 Oct 2006 10:03:19 +0100, "Peter T" <peter_t@discussions
wrote: I'm not quite sure what you are trying to do, perhaps something like this - Userform with image control named Image1 change the picture file name click on image to change zoom +/-25% Hi Peter, That's absolutely brilliant. Many thanks indeed ! I was quite pleased I managed to work outy where everything should go and get it working! Had my doubts to start with... Just 2 things remain (which I may be able to figure) - a default size that it always starts with, although I suspect this is now dependant on the picture size, and they aren't all the same. And, can a command button be placed on the picture, caption "Next' ? Or would this need to go somewhere else? Sometimes there's more than one associated image. A public variable keeps track of that. Many thanks, I got in over my depth a bit here but sort of know what I want, just not how to achieve it. Cheers - Kirk |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi again Kirk,
Some pointers. Zoom changes all controls in the container, so if your buttons are in the same container they'll change size, but could use a frame which is also a container. Try this Put one or two buttons at the top of the form (.top = 0) make both same height Add a frame named Frame1, with the frame selected add Image1 Extend the code to change dimensions of Frame1 to same as the picture but with its top = 0 + button. Also in all size/zoom changes make height of form = Frame1.height (previously adjusted from the Image1.height) + button.height + titlebar.height (from the API). Perhaps add a little extra to both height & width to allow for picture & frame borders. Change the zoom to Me.Frame1.Zoom = z Might want to restrict minimum form width to that of the right edge of the rightmost button, eg minFrmWidth = button2.left + button2.width + a-little-bit. In the previous example, make most of the code in the Initialize event a dedicated function that receives a string filename. Code in the initalize event something like sFile = "C:\mypicture.jpg" Call fnSetPicture sFile You can now call the same function from another button to load new pictures. To start with a default size: Decide if the default will be the X or Y dimension, let's say X After running fnSetPicture compare loaded width with defaultX, eg factor = Int(defaultX/Image1.Width * 100) Me.Frame.Zoom = factor store the factor as the current zoom setting Look at Zoom in help, gives ideas to add a scrollbar or spin to adjust zoom rather than the +/-25% in the example. A different approach would be not to use Zoom at all but scale the image's width & height (and resize form to suit). Regards, Peter T "kirkm" wrote in message ... On Thu, 19 Oct 2006 10:03:19 +0100, "Peter T" <peter_t@discussions wrote: I'm not quite sure what you are trying to do, perhaps something like this - Userform with image control named Image1 change the picture file name click on image to change zoom +/-25% Hi Peter, That's absolutely brilliant. Many thanks indeed ! I was quite pleased I managed to work outy where everything should go and get it working! Had my doubts to start with... Just 2 things remain (which I may be able to figure) - a default size that it always starts with, although I suspect this is now dependant on the picture size, and they aren't all the same. And, can a command button be placed on the picture, caption "Next' ? Or would this need to go somewhere else? Sometimes there's more than one associated image. A public variable keeps track of that. Many thanks, I got in over my depth a bit here but sort of know what I want, just not how to achieve it. Cheers - Kirk |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
adding a picture to a form | Excel Discussion (Misc queries) | |||
Picture on Form (VB) | Excel Programming | |||
Variable Picture in a Form | Excel Programming | |||
User Form Picture | New Users to Excel | |||
User form - Picture in the caption? | Excel Programming |