Sorry,应该是SetTextColorPrivate Declare Function SetTextColor Lib "gdi32.dll" (ByVal hdc As Long, ByVal crColor As Long) As Long Private Declare Function TextOut Lib "gdi32.dll" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long Private Declare Function GetWindowDC Lib "user32.dll" (ByVal hwnd As Long) As LongPrivate Sub Form_Click() Dim strShow As String, hdc As Long hdc = GetWindowDC(Me.hwnd) SetTextColor hdc, vbRed strShow = "显示字符串" TextOut hdc, 15, 15, strShow, LenB(strShow) End Sub注意这样画出来不是透明的。如果需要透明,再加上这些 Private Declare Function SetBkMode Lib "gdi32.dll" (ByVal hdc As Long, ByVal nBkMode As Long) As Long Private Const TRANSPARENT As Long = 1SetBkMode hdc, TRANSPARENT当然,把HDC改一下就可以了:)
注意啊不用表单的,直接操作内存DC,如果是表单或者picturebox直接设定前景色这个我知道.
Private Declare Function TextOut Lib "gdi32.dll" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function GetWindowDC Lib "user32.dll" (ByVal hwnd As Long) As LongPrivate Sub Form_Click()
Dim strShow As String, hdc As Long
hdc = GetWindowDC(Me.hwnd)
SetTextColor hdc, vbRed
strShow = "显示字符串"
TextOut hdc, 15, 15, strShow, LenB(strShow)
End Sub注意这样画出来不是透明的。如果需要透明,再加上这些
Private Declare Function SetBkMode Lib "gdi32.dll" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Const TRANSPARENT As Long = 1SetBkMode hdc, TRANSPARENT当然,把HDC改一下就可以了:)