You can get the border width with .width - .scalewidth (and the same for
height). Just offset the window size by those values to fit the required
inner size.
--
Dean Earley (dean....@icode.co.uk)
i-Catcher Development Team
iCode Systems
> It seems to work OK now, but I'm probably doing more math then is
> actually needed?
Yes, since you need your output in Twips, stay in twips....
Dim wid As Long, hgt As Long
Me.ScaleMode = vbTwips
Me.Picture = LoadPicture("C:\320x240.jpg")
wid = ScaleX(Me.Picture.Width, vbHimetric, vbTwips)
hgt = ScaleY(Me.Picture.Height, vbHimetric, vbTwips)
wid = wid + (Me.Width - Me.ScaleWidth)
hgt = hgt + (Me.Height - Me.ScaleHeight)
Me.Move Me.Left, Me.Top, wid, hgt
LFS
> >Yes, since you need your output in Twips, stay in twips....
>
> Asked over at VbForums too and got this answer.
> Me.Move Me.Left, Me.Top, _
> Me.Width - Me.ScaleX(Me.ScaleWidth, Me.ScaleMode, vbTwips) + _
> Me.ScaleX(Me.Picture.Width, vbHimetric, vbTwips), _
> Me.Height - Me.ScaleY(Me.ScaleHeight, Me.ScaleMode, vbTwips) + _
> Me.ScaleY(Me.Picture.Height, vbHimetric, vbTwips)
So is that more math, or less math than you were doing before?
If you consider addition and subtraction non-consequential, you
had 2 divisions, and 2 multiplications, plus 2 calls to Scale(XY).
I showed a method that used only 2 calls to Scale(XY), and the
above has 4 calls to Scale(XY).
I'd say, if you want to be certain, run timed tests on the bunch
and see where you stand....
LFS
--
Randy
ms mvp - visual basic
http://vbnet.mvps.org/
"Ed" <nos...@hotmail.com> wrote in message
news:v6t9e4he0couq0llk...@4ax.com...
> On Sat, 27 Sep 2008 07:09:28 -0500, "Larry Serflaten"
> <serf...@usinternet.com> wrote:
>
>>So is that more math, or less math than you were doing before?
>>
>>If you consider addition and subtraction non-consequential, you
>>had 2 divisions, and 2 multiplications, plus 2 calls to Scale(XY).
>>I showed a method that used only 2 calls to Scale(XY), and the
>>above has 4 calls to Scale(XY).
>>
>>I'd say, if you want to be certain, run timed tests on the bunch
>>and see where you stand....
>>
>>LFS
>>
>
> I understand that, I was just worried I was doing more then was
> necessary. One line of code is always nice if it's not a bottleneck tho.
> Cheers,
> Ed
In the Command1_Click event, change:
Form2.Picture1.Picture = LoadPicture(.FileName)
.... to ....
Form2.Picture2.Picture = LoadPicture(.FileName)
You can now delete Picture1 from form2 - it's not required. Once you test
and it works, rename picture2 to picture1 globally, just to be neat.
--
Randy
ms mvp - visual basic
http://vbnet.mvps.org/
"Ed" <nos...@hotmail.com> wrote in message
news:v7nle497ki05rbp5t...@4ax.com...
> On Thu, 2 Oct 2008 19:03:00 -0400, "Randy Birch"
> <rgb_rem...@mvps.org> wrote:
>
>>http://vbnet.mvps.org/code/forms/autoresizeform.htm
>
> That doesn't work correctly.
Ignore the previous post.
It wasn't debug code left in the page - the code is fine (my damn vb6's
mztools had the option to ask for control name to be set, meaning if you hit
the wrong button you get an unexpected control name. Which I accidently did
a few minutes ago. But I digress ...)
Please define "That doesn't work correctly" == what specifically is the
problem you see? Note that if you are trying to view small images, a form
can't be made smaller than the space required to display its non-client area
controls. If you need a form with a titlebar that will resize fairly small,
remove the min/max buttons.
--
Randy
ms mvp - visual basic
http://vbnet.mvps.org/
"Randy Birch" <rgb_rem...@mvps.org> wrote in message
news:uZX$FiKKJH...@TK2MSFTNGP04.phx.gbl...
You can test it simply by adding a pixbox to a form and sizing it to one
appropriate for this test. The load event sets up the pixbox. Run the
project, then double click the form to have it resize. You should see the 1
pixel black border of the pixbox bounding the left, bottom and right of the
form, aligned with the caption at the top (or a menu if such is on the
form), and the debug window will print out the size of the picturebox, and
the size of the client area of the form, which will be identical, e.g.,
picture 3375 2175
form 3375 2175
'-------------------
Option Explicit
Private Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long
Private Declare Function GetMenu Lib "user32" _
(ByVal hwnd As Long) As Long
Private Const SM_CYCAPTION = 4
Private Const SM_CYMENU = 15
Private Const SM_CXFRAME = 32
Private Const SM_CYFRAME = 33
Private twipsx As Long
Private twipsy As Long
Private Sub Form_Load()
twipsx = Screen.TwipsPerPixelX
twipsy = Screen.TwipsPerPixelY
With Picture1
.AutoSize = True
.Appearance = 0
.BackColor = &HFFFF80
End With
End Sub
Private Sub Form_DblClick()
AutoSizeToPicture Picture1
End Sub
Private Sub AutoSizeToPicture(pbox As PictureBox)
Dim vOffset As Long
Dim hOffset As Long
hOffset = (GetSystemMetrics(SM_CXFRAME) * 2) * twipsx
vOffset = (GetSystemMetrics(SM_CYCAPTION) +
(GetSystemMetrics(SM_CYFRAME)) * 2) * twipsx
'if the form also has a menu,
'account for that too
If GetMenu(Me.hwnd) <> 0 Then
vOffset = vOffset + (GetSystemMetrics(SM_CYMENU) * twipsy)
End If
'position the picture box and resize the form
With pbox
.Left = 0
.Top = 0
Me.Width = .Width + hOffset
Me.Height = .Height + vOffset
End With
'these values should be the same
'if the calculations worked
Debug.Print "picture", Picture1.Width, Picture1.Height
Debug.Print "form", Form1.ScaleWidth, Form1.ScaleHeight
End Sub
'-------------------
--
Randy Birch
ms mvp, visual basic
http://vbnet.mvps.org/
"Ed" <nos...@hotmail.com> wrote in message
news:uei2f4hjmh1l00lm8...@4ax.com...
> On Tue, 7 Oct 2008 14:28:46 -0400, "Randy Birch"
> <rgb_rem...@mvps.org> wrote:
>
>>Please define "That doesn't work correctly" == what specifically is the
>>problem you see?
>
> I deleted the code but from what I can gather is it used some hard coded
> values in figuring out how large the form should be, the forms right and
> bottom boarder covered some of the loaded images.
>
> Cheers,
> Ed