Results 1 to 10 of 10

Thread: [RESOLVED] Statusbar - Simple Style - Right Align Text

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Resolved [RESOLVED] Statusbar - Simple Style - Right Align Text

    Other than adding spaces to the Text in an attempt to right align,
    is there a solution to this problem?

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Statusbar - Simple Style - Right Align Text

    Quote Originally Posted by vb6forever View Post
    Other than adding spaces to the Text in an attempt to right align,
    is there a solution to this problem?
    You can't right align the SimpleText but you can do the same with one panel.
    Paste a new StausBar control in a form and this code to test:

    Code:
    Option Explicit
    
    Private Const SM_CXVSCROLL As Long = 2
    Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    
    Private Sub Form_Load()
        StatusBar1.Panels(1).Bevel = sbrNoBevel
        StatusBar1.Panels(1).Alignment = sbrRight
        StatusBar1.Panels(1).Text = "Testing"
    End Sub
    
    Private Sub Form_Resize()
        StatusBar1.Panels(1).Width = Me.ScaleWidth - (GetSystemMetrics(SM_CXVSCROLL) + 3) * Screen.TwipsPerPixelX
    End Sub

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Statusbar - Simple Style - Right Align Text

    Eduardo-:
    Thanks for responding. It is the SimpleText I need to right align.
    Will test your code in the am.

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Statusbar - Simple Style - Right Align Text

    When I said that "you can do the same" I meant that you can achieve the exact same result (visually).

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Statusbar - Simple Style - Right Align Text

    From the October 2001 MSDN CD docs:

    By default, text is left-aligned within the specified part of a status bar. You can embed tab characters (\ t) in the text to center or right-align it. Text to the right of a single tab character is centered, and text to the right of a second tab character is right-aligned.

    This works great when you have a fixed-size Form:

    Name:  sshot1.png
Views: 543
Size:  1.4 KB


    However, conventions have changed and Windows now (Win10.1809 and COMCTL32.OCX tested here) seems to always add a SizeGrip handle icon for a sizeable Form without fully "informing" the text operations part of the control:

    Name:  sshot2.png
Views: 580
Size:  1.4 KB


    So we're back to trying fixes. Here is one approach:

    Code:
    Option Explicit
    
    Private Enum SYSTEM_METRICS
        SM_CXSMICON = 49
    End Enum
    
    Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As SYSTEM_METRICS) As Long
    
    Private Sub Form_Load()
        Dim NoBreakSpace As String
        Dim N As Long
    
        With StatusBar1
            NoBreakSpace = ChrW$(&HA0&)
            'We assume that Form1.Font and StatusBar1.Font are both Segoe UI 9 or the
            'system dialog font you would ideally query for:
            N = Int(ScaleX(GetSystemMetrics(SM_CXSMICON), vbPixels, ScaleMode) _
                    / TextWidth(NoBreakSpace) _
                    + 0.5)
            .SimpleText = "Left" & vbTab & "Center" & vbTab & "Right" _
                        & String$(N, NoBreakSpace)
        End With
    End Sub
    Name:  sshot3.png
Views: 536
Size:  1.4 KB
    Last edited by dilettante; May 19th, 2019 at 07:11 AM.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Statusbar - Simple Style - Right Align Text

    There may be a cleaner workaround, I just haven't found it.

  7. #7
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Statusbar - Simple Style - Right Align Text

    Quote Originally Posted by dilettante View Post
    There may be a cleaner workaround, I just haven't found it.

    Well, since we talk about "SimpleText"-output on a "small rectangular stripe at the bottom of a Form"...
    - a simple PictureBox with AlignBottom and a (left- or right-align) Label on it could work
    - as would your own Private UserControl-Module with "Alignable=True" and a few Lines of code in it (as e.g. the one below)

    Code:
    Option Explicit
    
    Private mText  As String
    
    Public Sub SetSimpleText(Text As String, Optional FontName$ = "Arial", Optional ByVal FontSize! = 10)
      mText = Text
      UserControl.FontName = FontName
      UserControl.FontSize = FontSize
      AutoRedraw = True
      ScaleMode = vbPixels
      Redraw
    End Sub
     
    Private Sub Redraw()
      Dim T() As String: T = Split(mText, vbTab)
      Cls
        CurrentY = (ScaleHeight - TextHeight("")) / 2
        If UBound(T) >= 0 Then CurrentX = 3: Print T(0);
        If UBound(T) >= 1 Then CurrentX = (ScaleWidth - TextWidth(T(1))) / 2: Print T(1);
        If UBound(T) >= 2 Then CurrentX = (ScaleWidth - TextWidth(T(2))) - 3: Print T(2);
      Refresh
    End Sub
     
    Private Sub UserControl_Resize()
      Redraw
    End Sub
    FormCode:
    Code:
    Private Sub Form_Load()
      ucStatusBar1.SetSimpleText Replace("Left<>Middle<>Right", "<>", vbTab)
    End Sub
    Olaf

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Statusbar - Simple Style - Right Align Text

    It depends.

    The SimpleText style seems to be there in order to temporarily flip to alternative text when some sort of event occurs you want to notify the user of. Flipping the style back gets your original set of panels back without altering them.

    But if one merely wants to simulate a StatusBar that is always in SimpleText mode you're right. Lots of possibilities. I often use a Label for that myself.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Statusbar - Simple Style - Right Align Text

    Thanks to all for their posts. Am sure can get one to work.

    -------------
    FWIW (dilettante post #5)
    -------------
    The easiest, if it will work, is embedding a \t \t at the front of the text.
    For VB5 under Window7-Pro, I could never get other than left alignment as the statusbar interpreted the \t as part of the literal (text). However, doing it this way works:
    Code:
    Private Sub Form_Load()
    
    StatusBar1.SimpleText = Chr(9) & Chr(9) & "Align Right"
    
    End Sub
    Last edited by vb6forever; May 19th, 2019 at 09:12 AM. Reason: Correction

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] Statusbar - Simple Style - Right Align Text

    The \t is C-speak for VB's vbTab predefined constant.

Posting Permissions

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



Click Here to Expand Forum to Full Width