如果一个控件都不用的话,只能用drawtext进行模拟了:
Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Const DT_CENTER = &H1
Const OPAQUE = 2
Dim w As Long, h As Long
Dim s As String
Private Sub Form_Load()
Me.ScaleMode = 3
s = "this is test"
h = Me.TextHeight(s)
w = Me.TextWidth(s)
Debug.Print w
SetBkMode Me.hdc, OPAQUE
SetBkColor Me.hdc, vbGreen
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Cls
Dim R As RECT
R.Left = X + 10
R.Top = Y
R.Bottom = Y + h
R.Right = X + w + 10
DrawText Me.hdc, s, -1, R, DT_CENTER
End Sub