Consulting

Results 1 to 7 of 7

Thread: Frame Caption

  1. #1

    Frame Caption

    Hi,

    I have a frame on my UserForm and what I want to know; is there any way to adjust the caption of a frame to the center instead of upper left hand side

    Thanks in advance

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Not directly, but if you set the caption to nothing you can then use a label positioned in the centre, this will have the same visual effect
    K :-)

  3. #3
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Hi,

    I don't believe there is a property that will align the frames caption.

    This routine will centered the text by adding padding characters to the text.
    Note the border on the top left of the frame will not appear.

    Sub CenterFrameTitle(MyFrame As MSForms.Frame)
    
        Dim strBuf As String
        Dim labTemp As MSForms.Label
        
        Set labTemp = Me.Controls.Add("Forms.Label.1", "labTemp", True)
        strBuf = Trim(MyFrame.Caption)
        With labTemp
            With .Font
                .Name = MyFrame.Font.Name
                .Size = MyFrame.Font.Size
                .Bold = MyFrame.Font.Bold
                .Italic = MyFrame.Font.Italic
            End With
            .WordWrap = False
            .AutoSize = True
            .Caption = strBuf
            Do While .Width < (MyFrame.Width - 20) ' frame title insert slightly
                strBuf = " " & strBuf & " "        ' pad caption
                .Caption = strBuf
            Loop
        End With
        Controls.Remove "labtemp"
        Set labTemp = Nothing
        MyFrame.Caption = RTrim(strBuf)
    
    End Sub
    Hi Killian, how close can you get the label to the border of the frame?
    when I tried that the label is either partially covered by the frame or the label becomes contained within the frame and the top half vanishes.
    Cheers
    Andy

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    My apologies... I just looked for a project where I did this and guess what? I found I couldn't. My solution at the time was to use an image control with the SpecialEffect property set to etched with a label where I wanted it (I actually wanted two captions on the frame but with the etched line between them.
    This was fine for me since it was a purely cosmetic use of frames. If you need any of the frame's control functionality it won't help
    K :-)

  5. #5
    Thanks for the answers,

    Andy,

    I tryed the solution you mentioned and I think without upper left line, the frame didn't look good.So better off using the default caption position.

    Thanks again


  6. #6
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Hi,

    How about adapting Killian suggestion.

    Use 2 labels, one to hold the text and the other to provide the border.
    On top of that place a frame control. Format the frame to have no caption and no border.

    It now looks like the frame has a centered title and the real frame control can be a container for other controls.
    Cheers
    Andy

  7. #7
    Hi Andy,

    I have attached a file that the result of Killian's answer and I have to say it is looking good.

    Killian,

    Thanks for the tip

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •