Discussion:
VB6 Frames
(too old to reply)
scbs29
2012-04-28 16:12:17 UTC
Permalink
Hello all
probably simple question

I have image controls within frames. I calculate to fit the images to
the frame dimensions, but if the frame has a borderstyle 1, fixed
single, the images still extend to the frame edges. Is there a way of
only extending the images to fit within the border ?

TIA for any advice

remove fred before emailing
Registered Linux User 490858
Auric__
2012-04-29 00:24:26 UTC
Permalink
Post by scbs29
probably simple question
I have image controls within frames. I calculate to fit the images to
the frame dimensions, but if the frame has a borderstyle 1, fixed
single, the images still extend to the frame edges. Is there a way of
only extending the images to fit within the border ?
Have you tried checking the border style when you load the image? Something
like this might work (if using a Picture control; Image controls don't
support the Change event so you'd have to run the sub from your code):

Const onepixel = 14
Const twopixels = 28

Private Sub Picture1_Change()
With Picture1
If Frame1.BorderStyle And (Len(.Tag) < 1) Then
.Tag = "moved"
.Left = .Left + onepixel
.Top = .Top + onepixel
.Width = .Width - twopixels
.Height = .Height - twopixels
ElseIf Len(.Tag) And (0 = Frame1.BorderStyle) Then
.Tag = ""
.Left = .Left - onepixel
.Top = .Top - onepixel
.Width = .Width + twopixels
.Height = .Height + twopixels
End If
End With
End Sub
--
When did I want to be lonely? When did I want to be cold?
scbs29
2012-04-29 09:10:46 UTC
Permalink
On Sun, 29 Apr 2012 00:24:26 +0000 (UTC), "Auric__"
Post by Auric__
Post by scbs29
probably simple question
I have image controls within frames. I calculate to fit the images to
the frame dimensions, but if the frame has a borderstyle 1, fixed
single, the images still extend to the frame edges. Is there a way of
only extending the images to fit within the border ?
Have you tried checking the border style when you load the image? Something
like this might work (if using a Picture control; Image controls don't
Const onepixel = 14
Const twopixels = 28
Private Sub Picture1_Change()
With Picture1
If Frame1.BorderStyle And (Len(.Tag) < 1) Then
.Tag = "moved"
.Left = .Left + onepixel
.Top = .Top + onepixel
.Width = .Width - twopixels
.Height = .Height - twopixels
ElseIf Len(.Tag) And (0 = Frame1.BorderStyle) Then
.Tag = ""
.Left = .Left - onepixel
.Top = .Top - onepixel
.Width = .Width + twopixels
.Height = .Height + twopixels
End If
End With
End Sub
Thanks for the reply.
I have tried your suggestion, but had to multiply the const values by
10 to show any effect. If I have to set a particular value for these,
however, then surely they will only work correctly at the screen
resolution at which they are tested.

remove fred before emailing
Registered Linux User 490858
Deanna Earley
2012-04-30 07:59:44 UTC
Permalink
Post by scbs29
On Sun, 29 Apr 2012 00:24:26 +0000 (UTC), "Auric__"
Post by Auric__
Post by scbs29
probably simple question
I have image controls within frames. I calculate to fit the images to
the frame dimensions, but if the frame has a borderstyle 1, fixed
single, the images still extend to the frame edges. Is there a way of
only extending the images to fit within the border ?
Have you tried checking the border style when you load the image? Something
like this might work (if using a Picture control; Image controls don't
Const onepixel = 14
Const twopixels = 28
Private Sub Picture1_Change()
With Picture1
If Frame1.BorderStyle And (Len(.Tag)< 1) Then
.Tag = "moved"
.Left = .Left + onepixel
.Top = .Top + onepixel
.Width = .Width - twopixels
.Height = .Height - twopixels
ElseIf Len(.Tag) And (0 = Frame1.BorderStyle) Then
.Tag = ""
.Left = .Left - onepixel
.Top = .Top - onepixel
.Width = .Width + twopixels
.Height = .Height + twopixels
End If
End With
End Sub
Thanks for the reply.
I have tried your suggestion, but had to multiply the const values by
10 to show any effect. If I have to set a particular value for these,
however, then surely they will only work correctly at the screen
resolution at which they are tested.
Use Screen.TwipsPerPixelX/Y as the multiplier.
--
Deanna Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
Mike Williams
2012-04-29 12:18:25 UTC
Permalink
Hello all, probably simple question. I have image controls
within frames. I calculate to fit the images to the frame
dimensions, but if the frame has a borderstyle 1, fixed
single, the images still extend to the frame edges. Is there
a way of only extending the images to fit within the border ?
I don't know why you are putting Image Controls into Frames nor how many
images you want to place in each Frame and there may be a better way of
doing whatever job it is you want to do (a PictureBox as a container for
your images for example, which will allow you to do a lot more stuff), so
the following is just an explanation of how to fit a single Image Control
into a Frame that has a border so that the Image exactly fills the Frame
without flowing into its borders. Naturally this will cause the image to
have an incorrect aspect ratio unless you also take care to size the Frame
accordingly, but the purpose of the explanation is purely to show you how to
handle the Frame's borders and the Frame's font size (since I do not know
exactly what job you want to do).

The borders of a VB Frame with a FixedSingle BorderStyle property are 2
pixels thick (not one) and the position of the top border is below the Top
property of the Frame by an amount equal to half the text height of the
Frame's font, rounded down if the text height is an odd number. This applies
whether the Frame's Caption is empty or not. The easiest way to get the
height of the Frame's font is to assign it to an otherwise unused PictureBox
so that you can use the PictureBox's TextHeight property (picDummy in the
example). The following code should do it for you (a Frame Control without a
border is different of course but I'm sure you already know how to handle
that yourself so the following example code is for Frames with a border).
Note that the Image (using the following example code) will fit exactly
within the visible borders of the Fixedsingle BorderStyle Frame, and
therefore only the upper half of the Fram'es Caption will be visible. If
that is not what you want then you should find it fairly easy to adjust the
code accordingly, otherwise post again.

Mike

Private Sub Command1_Click()
Dim TwoPixels As Long
picDummy.ScaleMode = vbTwips
picDummy.Visible = False
TwoPixels = Me.ScaleX(2, vbPixels, vbTwips)
Set Image1.Container = Frame1
Image1.Left = TwoPixels
Set picDummy.Font = Frame1.Font
Image1.Top = Int(picDummy.TextHeight("x") / 2) + TwoPixels
Image1.Width = Frame1.Width - (TwoPixels * 2)
Image1.Height = Frame1.Height - Image1.Top - TwoPixels
End Sub
Mike Williams
2012-04-30 10:25:44 UTC
Permalink
Post by Mike Williams
The borders of a VB Frame with a FixedSingle BorderStyle
property are 2 pixels thick and the position of the top border
is below the Top property of the Frame by an amount equal
to half the text height of the Frame's font, rounded down if
the text height is an odd number . . .
In the code example in my previous post I intended to round down the "half
Frame Caption text height" to the nearest whole pixel but I inadvertently
rounded it down to the nearest whole twip. This makes no difference and it
works fine on machines running at an odd number of twips per pixel (the
majority of machines) but it leads to a vertical positioning error of one
pixel at some font sizes on machines running at an even number of twips per
pixel. Here is my original code modified so that it fixes that problem:

Mike

Private Sub Command1_Click()
Dim TwoPixels As Long
picDummy.ScaleMode = vbPixels
picDummy.Visible = False
TwoPixels = Me.ScaleX(2, vbPixels, vbTwips)
Set Image1.Container = Frame1
Image1.Left = TwoPixels
Set picDummy.Font = Frame1.Font
Image1.Top = ScaleY(Int(picDummy.TextHeight("x") / 2), _
vbPixels, vbTwips) + TwoPixels
Image1.Width = Frame1.Width - (TwoPixels * 2)
Image1.Height = Frame1.Height - Image1.Top - TwoPixels
End Sub
scbs29
2012-04-30 11:52:25 UTC
Permalink
Post by scbs29
Hello all
probably simple question
I have image controls within frames. I calculate to fit the images to
the frame dimensions, but if the frame has a borderstyle 1, fixed
single, the images still extend to the frame edges. Is there a way of
only extending the images to fit within the border ?
TIA for any advice
remove fred before emailing
Registered Linux User 490858
Thank you all for the advice.

What I am doing is displaying a form with images. These images are
either jpg or png and I am using a control called aicAlphaImage to
display them. I have a set of forms to display any number of images
from 1 to 12. The reason for the frames is to separate the images on
display. Thers is only one image per frame. Images are children of the
frames.

I was thinking that there may be something like a frame.border
property which I could access, but it seems that I was wrong.
I have had another look at it, and have come up with

With Form
' set width and height adjustments
intWad = .Frame1.Width / 10
intHad = .Frame1.Height / 10

' calc position for top of buttons and label on form
lngTop = .ScaleHeight - (.cmdExit.Height * 3)
.Label1.Top = lngTop
.cmdPrevious.Top = lngTop
.cmdClose.Top = lngTop
.cmdExit.Top = lngTop
.cmdNext.Top = lngTop
.cmdMainMenu.Top = lngTop

' lngW = width of form
' lngH = height on form above buttons for frames
lngW = .ScaleWidth
lngH = .ScaleHeight - (.cmdExit.Height * 3)

'left, top, width and height of frame
'in this case, 3 rows of frames
lngLeft = 0
lngTop = 0
.Frame1.Left = lngLeft
.Frame1.Top = lngTop
.Frame1.Width = lngW / 3
.Frame1.Height = lngH / 3
'image size to fit within the frame
.Image1.Left = intWad
.Image1.Top = intHad
.Image1.Width = .Frame1.Width - (2 * intWad)
.Image1.Height = .Frame1.Height - (2 * intHad)

so far, this seems to be working ok.

remove fred before emailing
Registered Linux User 490858
Mike Williams
2012-04-30 12:43:21 UTC
Permalink
Post by scbs29
I was thinking that there may be something like a
frame.border property which I could access, but
it seems that I was wrong.
There is a BorderStyle property for Frames which can be set to either 0 (no
border) or 1 (FixedSingle) but I gathered from your original post that you
already knew about that? Or have I misunderstood the above statement of
yours?

Regarding the code you have just posted, it seems to be rather strange so I
am quite surprised that it is working okay for you, unless you have missed
telling us something? For example, you are setting an IntHad property to one
tenth the Height of a Frame and then you are /afterwards/ changing the
Height of the Frame to the height of the Image plus (2 * IntHad). So, the
size of the actual horizontal borders (intHad) will depend on the Heght of
the frame as it was /before/ the Frame's height was altered to take account
of the height of the Image, which as far as i can see could have been
anything at all. There is a similar problem with IntWad. This just isn't
right to my mind. Also, you are completely failing to take account of the
fact that the top position and the height of the Frame's border is /not/ the
same as the Top or Height properties of the frame itself. It all sounds a
bit "iffy" to me.

Mike
scbs29
2012-05-02 12:39:48 UTC
Permalink
On Mon, 30 Apr 2012 13:43:21 +0100, "Mike Williams"
Post by Mike Williams
Post by scbs29
I was thinking that there may be something like a
frame.border property which I could access, but
it seems that I was wrong.
There is a BorderStyle property for Frames which can be set to either 0 (no
border) or 1 (FixedSingle) but I gathered from your original post that you
already knew about that? Or have I misunderstood the above statement of
yours?
Regarding the code you have just posted, it seems to be rather strange so I
am quite surprised that it is working okay for you, unless you have missed
telling us something? For example, you are setting an IntHad property to one
tenth the Height of a Frame and then you are /afterwards/ changing the
Height of the Frame to the height of the Image plus (2 * IntHad). So, the
size of the actual horizontal borders (intHad) will depend on the Heght of
the frame as it was /before/ the Frame's height was altered to take account
of the height of the Image, which as far as i can see could have been
anything at all. There is a similar problem with IntWad. This just isn't
right to my mind. Also, you are completely failing to take account of the
fact that the top position and the height of the Frame's border is /not/ the
same as the Top or Height properties of the frame itself. It all sounds a
bit "iffy" to me.
Mike
Thanks for the reply.
Yes, you are right, I did have setting intWad and intHad in the wrong
place. I have now moved them to after setting the width and height of
the first frame, since all frames will be the same size.
I knew about the BorderStyle property, but could not find any
reference to finding out the amount of the frame the border took up,
ie. is the border at 10% of the height from the top, 20%, how do the
position, height and width of the frame within the border relate to
those of the entire frame, what are the position, height and width of
the border wrt the frame, how can you find out? The idea is to fit the
image control within the border with borderstyle 1.
How I have done it works, but it does not seem a very 'elegant'
solution.


remove fred before emailing
Registered Linux User 490858
Mike Williams
2012-05-02 20:21:20 UTC
Permalink
Post by scbs29
I knew about the BorderStyle property, but could not
find any reference to finding out the amount of the
frame the border took up, ie. is the border at 10% of
the height from the top, 20%, or . . . etc, etc
I have already explained this in my response to your initial post in this
thread, but I'll run through it again. The Width and Height properties of a
Frame Control with a BorderStyle of 1 (Fixed Single) relate to the overall
size of the Frame, including its borders and including the area where the
Caption Text lives at the top. All four borders are two pixels thick.

The left, right and bottom borders are all drawn at the very edge of the
Frame. As an example, if you set the Width property of a Frame Control to 5
pixels then the part of the frame that is inside its left and right borders
would be only 1 pixel wide.

The Top border is different in that it is /not/ at the very top edge of the
frame. The Top border is positioned /below/ the top edge of the frame by an
amount that is equal to half of the TextHeight of the Frame's Caption,
rounded down to the nearest whole pixel value if the Caption's TextHeight is
an odd number of pixels. You can see this more clearly if you place a Frame
Control on a Form and set the Form's Backcolour to red and the Frame's
BackColor to red. You might like to actually do that before you read the
rest of this message . . .

Me.BackColor = vbYellow
Frame1.BackColor = vbRed

Regarding positioning of things in a Frame, if you place an Image Control in
the Frame (so that the Frame is its container) and if you position the Image
Control at position (0, 0) then the Image Control will cover the left border
of the Frame and it will cover the top border and also the Caption text.
Again, you might like to try that before moving on. Place an Image Control
on the same Form above and set its Picture property to whatever picture you
wish to display and do the following (use a standard VB6 Image Control for
these tests):

Private Sub Command1_Click()
Me.BackColor = vbYellow
Frame1.BackColor = vbRed
Image1.Stretch = True
Set Image1.Container = Frame1
Image1.Width = ScaleX(36, vbPixels, vbTwips)
Image1.Height = ScaleX(30, vbPixels, vbTwips)
Image1.Move 0, 0
End Sub

In order to position the Image so that it is /inside/ the Frame's borders
and exactly fills the Frame right up to those borders then you need to set
the Image's Left property to 2 pixels (converted to twips) and its Top
property to 2 pixels below the start position of the frame's Top border
(also converted to twips), which of course your code will need to calculate
by examining the TextHeight of the Frame's Caption (this value will depend
on the font the frame uses) and dividing the value by two and rounding it
down to the nearest whole pixel, as mentioned above. Place a PictureBox on
the same Form as above and set the PictureBox's Name property to picDummy.
Then use the following code:

Private Sub Command2_Click()
Dim blockwide As Long, blockhigh As Long
Dim TopMargin As Long, OtherMargins As Long
Dim TwoPixels As Long
Picture1.ScaleMode = vbPixels
Picture1.Visible = False
Me.BackColor = vbYellow
Frame1.BackColor = vbRed
Image1.Stretch = True
Set Image1.Container = Frame1
TwoPixels = Me.ScaleX(2, vbPixels, vbTwips)
Set Picture1.Font = Frame1.Font
TopMargin = ScaleY(Int(Picture1.TextHeight("x") / 2), _
vbPixels, vbTwips) + TwoPixels
OtherMargins = ScaleX(2, vbPixels, vbTwips)
blockwide = ScaleX(Frame1.Width, Me.ScaleMode, vbTwips) _
- (OtherMargins * 2)
blockhigh = ScaleY(Frame1.Height, Me.ScaleMode, vbTwips) _
- (TopMargin + OtherMargins)
Set Image1.Container = Frame1
Image1.Stretch = True
Image1.Move OtherMargins, TopMargin, blockwide, blockhigh
End Sub

The Image should exactly fill the entire Frame within its borders. It will
overwrite the bottom part of the Frame's Caption though, because we have
positioned it so that it starts immediately below the top border of the
frame, and the Frame's Caption is partly below that border, but you can
easily write a bit of extra code to fix that problem. The above code is
merely to visually shown what I have explained above. The additional code
required to position it below the Caption text is very straightforward, but
I am not sure at the moment whether you are actually using the Caption text
of the Frame, or whether you have set it as an empty string. Perhaps you
might like to post again with the answer to that one. If you are not
actually using the Caption then it is possible to set up the Frame so the
top border is exactly at the very top of the frame, which might be useful
for you depending on what you are doing.

Naturally, simply sizing the Image so that it fills the Frame is not usually
a good thing to do because you have said that your Frames are all the same
size and it is quite likely that the aspect ratio of the Frame (or the frame
within its borders) is not the same as the aspect ratio of the original
image you are using, so you will usually want to add some code the size the
Image so that it sits centrally within the frame and fills as much as
possible of the Frame without stretching the Image it in such a way that it
changes its aspect ratio, but you haven't mentioned aspect ratio and so I
don't know what you intend to do in that respect.

Mike

Loading...