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


Groups > comp.lang.basic.visual.misc > #1062

Re: VB6 Frames

From "Mike Williams" <Mike@WhiskyAndCoke.com>
Newsgroups comp.lang.basic.visual.misc
Subject Re: VB6 Frames
Date 2012-05-02 21:21 +0100
Organization A noiseless patient Spider
Message-ID <jns4uk$kpc$1@dont-email.me> (permalink)
References <535op7d1eqve0prjlcl8m73fl7finp8pgd@4ax.com> <qeusp7lg99qcqet6lvsjjkp1icv063lklf@4ax.com> <jnm1cr$sop$1@dont-email.me> <m4a2q7hrts4joa4j04964tdtq1tf3oosl1@4ax.com>

Show all headers | View raw


"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

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Find similar


Thread

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

csiph-web