Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #1047 > unrolled thread

VB6 Frames

Started byscbs29 <scbs29@fred.talktalk.net>
First post2012-04-28 17:12 +0100
Last post2012-05-02 21:21 +0100
Articles 10 — 4 participants

Back to article view | Back to comp.lang.basic.visual.misc


Contents

  VB6 Frames scbs29 <scbs29@fred.talktalk.net> - 2012-04-28 17:12 +0100
    Re: VB6 Frames "Auric__" <not.my.real@email.address> - 2012-04-29 00:24 +0000
      Re: VB6 Frames scbs29 <scbs29@fred.talktalk.net> - 2012-04-29 10:10 +0100
        Re: VB6 Frames Deanna Earley <dee.earley@icode.co.uk> - 2012-04-30 08:59 +0100
    Re: VB6 Frames "Mike Williams" <Mike@WhiskyAndCoke.com> - 2012-04-29 13:18 +0100
      Re: VB6 Frames "Mike Williams" <Mike@WhiskyAndCoke.com> - 2012-04-30 11:25 +0100
    Re: VB6 Frames scbs29 <scbs29@fred.talktalk.net> - 2012-04-30 12:52 +0100
      Re: VB6 Frames "Mike Williams" <Mike@WhiskyAndCoke.com> - 2012-04-30 13:43 +0100
        Re: VB6 Frames scbs29 <scbs29@fred.talktalk.net> - 2012-05-02 13:39 +0100
          Re: VB6 Frames "Mike Williams" <Mike@WhiskyAndCoke.com> - 2012-05-02 21:21 +0100

#1047 — VB6 Frames

Fromscbs29 <scbs29@fred.talktalk.net>
Date2012-04-28 17:12 +0100
SubjectVB6 Frames
Message-ID<535op7d1eqve0prjlcl8m73fl7finp8pgd@4ax.com>
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

[toc] | [next] | [standalone]


#1049

From"Auric__" <not.my.real@email.address>
Date2012-04-29 00:24 +0000
Message-ID<XnsA043B1122B58Bauricauricauricauric@88.198.244.100>
In reply to#1047
scbs29 wrote:

> 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?

[toc] | [prev] | [next] | [standalone]


#1050

Fromscbs29 <scbs29@fred.talktalk.net>
Date2012-04-29 10:10 +0100
Message-ID<371qp71hl0hbe2aej6h6hb588np6iduq9b@4ax.com>
In reply to#1049
On Sun, 29 Apr 2012 00:24:26 +0000 (UTC), "Auric__"
<not.my.real@email.address> wrote:

>scbs29 wrote:
>
>> 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

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

[toc] | [prev] | [next] | [standalone]


#1052

FromDeanna Earley <dee.earley@icode.co.uk>
Date2012-04-30 08:59 +0100
Message-ID<jnlgpe$o0f$1@speranza.aioe.org>
In reply to#1050
On 29/04/2012 10:10, scbs29 wrote:
> On Sun, 29 Apr 2012 00:24:26 +0000 (UTC), "Auric__"
> <not.my.real@email.address>  wrote:
>
>> scbs29 wrote:
>>
>>> 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
>
> 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 (dee.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.)

[toc] | [prev] | [next] | [standalone]


#1051

From"Mike Williams" <Mike@WhiskyAndCoke.com>
Date2012-04-29 13:18 +0100
Message-ID<jnjbho$19r$1@dont-email.me>
In reply to#1047
"scbs29" <scbs29@fred.talktalk.net> wrote in message 
news:535op7d1eqve0prjlcl8m73fl7finp8pgd@4ax.com...
>
> 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



[toc] | [prev] | [next] | [standalone]


#1053

From"Mike Williams" <Mike@WhiskyAndCoke.com>
Date2012-04-30 11:25 +0100
Message-ID<jnlpa5$itf$1@dont-email.me>
In reply to#1051
"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message 
news:jnjbho$19r$1@dont-email.me...
>
> 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



[toc] | [prev] | [next] | [standalone]


#1054

Fromscbs29 <scbs29@fred.talktalk.net>
Date2012-04-30 12:52 +0100
Message-ID<qeusp7lg99qcqet6lvsjjkp1icv063lklf@4ax.com>
In reply to#1047
On Sat, 28 Apr 2012 17:12:17 +0100, scbs29 <scbs29@fred.talktalk.net>
wrote:

>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

[toc] | [prev] | [next] | [standalone]


#1055

From"Mike Williams" <Mike@WhiskyAndCoke.com>
Date2012-04-30 13:43 +0100
Message-ID<jnm1cr$sop$1@dont-email.me>
In reply to#1054
"scbs29" <scbs29@fred.talktalk.net> wrote in message 
news:qeusp7lg99qcqet6lvsjjkp1icv063lklf@4ax.com...
> On Sat, 28 Apr 2012 17:12:17 +0100, scbs29 <scbs29@fred.talktalk.net>
> wrote:
> 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


[toc] | [prev] | [next] | [standalone]


#1061

Fromscbs29 <scbs29@fred.talktalk.net>
Date2012-05-02 13:39 +0100
Message-ID<m4a2q7hrts4joa4j04964tdtq1tf3oosl1@4ax.com>
In reply to#1055
On Mon, 30 Apr 2012 13:43:21 +0100, "Mike Williams"
<Mike@WhiskyAndCoke.com> wrote:

>"scbs29" <scbs29@fred.talktalk.net> wrote in message 
>news:qeusp7lg99qcqet6lvsjjkp1icv063lklf@4ax.com...
>> On Sat, 28 Apr 2012 17:12:17 +0100, scbs29 <scbs29@fred.talktalk.net>
>> wrote:
>> 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

[toc] | [prev] | [next] | [standalone]


#1062

From"Mike Williams" <Mike@WhiskyAndCoke.com>
Date2012-05-02 21:21 +0100
Message-ID<jns4uk$kpc$1@dont-email.me>
In reply to#1061
"scbs29" <scbs29@fred.talktalk.net> wrote in message 
news:m4a2q7hrts4joa4j04964tdtq1tf3oosl1@4ax.com...
>
> 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.basic.visual.misc


csiph-web