-
May 18th, 2019, 08:27 PM
#1
Thread Starter
Fanatic Member
[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?
-
May 18th, 2019, 09:43 PM
#2
Re: Statusbar - Simple Style - Right Align Text
Originally Posted by vb6forever
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
-
May 19th, 2019, 12:55 AM
#3
Thread Starter
Fanatic Member
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.
-
May 19th, 2019, 01:43 AM
#4
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).
-
May 19th, 2019, 07:03 AM
#5
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:
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:
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
Last edited by dilettante; May 19th, 2019 at 07:11 AM.
-
May 19th, 2019, 07:13 AM
#6
Re: Statusbar - Simple Style - Right Align Text
There may be a cleaner workaround, I just haven't found it.
-
May 19th, 2019, 08:30 AM
#7
Re: Statusbar - Simple Style - Right Align Text
Originally Posted by dilettante
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
-
May 19th, 2019, 08:48 AM
#8
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.
-
May 19th, 2019, 08:59 AM
#9
Thread Starter
Fanatic Member
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
-
May 19th, 2019, 11:32 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|