我正在修复基于Visual Basic 6代码构建的旧应用程序。要求在表单底部添加状态栏。我的状态栏如下:
我可以正确显示文本,但我也想添加红色背景色。我发现StatusBar面板没有这样的选项。当我打开StatusBar的属性时,它显示如下:
我发现我可以添加图片。但是当我添加红色图片时,文字将被图片覆盖。我被困住了。任何建议都会有所帮助。谢谢!
更新
我只是使用了comment中提供的@ÉtienneLaneville链接中的代码。添加了背景色和文本。
这是我调用该函数的代码:
name: str_1
type: (Int8,Int8,Int8)
value: (72,101,108,111,32,119,114,100,33,0)
swift string: Optional("Hello world!\0")
-----------------
name: str_2
type: (Int8,0)
swift string: Optional("Hello world!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
-----------------
name: str_3
type: UnsafeMutablePointer<Int8>
value: 0x000000010e8c5d40
swift string: Optional("Hello world!")
-----------------
name: str_4
type: (UInt8,UInt8,UInt8)
value: (72,0)
swift string: Optional("Hello world \0")
-----------------
name: str_5
type: UnsafeMutablePointer<UInt8>
value: 0x000000010e8c5d80
swift string: Optional("Hello world ")
-----------------
name: str_6
type: (UInt8,0)
swift string: Optional("Hello world!\0")
-----------------
name: str_7
name: str_8
type: UnsafeMutablePointer<UInt8>
value: 0x000000010e8c0ae0
swift string: Optional("")
-----------------
Optional("Hello world!\0")
Optional("Hello world!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
Optional("Hello world!")
Optional("Hello world \0")
Optional("Hello world ")
Optional("Hello world!\0")
Optional("")
Optional("")
但是文本位置如下:
我必须像下面这样放置文本才能定位它,因为该任务目前很紧急,我没有时间进行更多研究。
PanelText StatusBar1,9,"ATM (" & cntATM & ")",QBColor(12),QBColor(0)
下面是我的输出:
更新2
我尝试了Brian M Stafford提供的代码。但是我得到了相同的结果。文本仍不在中心(或向左)。下面是我的代码和状态栏的屏幕截图:
功能:
PanelText StatusBar1,"ATM (" & cntATM & ") ",QBColor(0)
API:
Private Sub PanelText(sb As StatusBar,pic As PictureBox,Index As Long,aText As String,bkColor As Long,_
fgColor As Long,lAlign As Integer)
Dim R As RECT
SendMessage sb.hWnd,SB_GETRECT,Index - 1,R
With pic
Set .Font = sb.Font
.Move 0,(R.Right - R.Left + 2) * Screen.TwipsPerPixelX,(R.Bottom - R.Top) * Screen.TwipsPerPixelY
.BackColor = bkColor
.Cls
.ForeColor = fgColor
.CurrentY = (.Height - .TextHeight(aText)) \ 2
Select Case lAlign
Case 0 ' Left Justified
.CurrentX = 0
Case 1 ' Right Justified
.CurrentX = .Width - .TextWidth(aText) - Screen.TwipsPerPixelX * 2
Case 2 ' Centered
.CurrentX = (.Width - .TextWidth(aText)) \ 2
End Select
pic.Print aText
sb.Panels(Index).Text = aText
sb.Panels(Index).Picture = .Image
End With
End Sub
调用函数:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const WM_USER = &H400
Private Const SB_GETRECT = (WM_USER + 10)
Private Declare Function SendMessage Lib _
"user32" Alias "SendMessageA" (ByVal hWnd As _
Long,ByVal wMsg As Long,ByVal wParam As _
Long,lParam As Any) As Long
我不知道为什么。可能是我遗漏了一些东西,或者是我为StatusBar1或picPanel(PictureBox)设置了一些属性值。
解决方案
我设置pictureBox,属性AutoRedraw = True,并设置StatusBar,Panel,Alignment = sbrLeft。一切正常。