在窗体上添加个command按钮
然后复制以下代码就可以了
Option Explicit Private Const FW_NORMAL = 400 Private Const ANSI_CHARSET = 0 Private Const FF_MODERN = 48 Private Const PROOF_QUALITY = 2 Private Declare Function TextOut Lib "gdi32" 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 CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Type LOGFONT lfHeightAs Long lfWidthAs Long lfEscapementAs Long lfOrientationAs Long lfWeightAs Long lfItalicAs Byte lfUnderlineAs Byte lfStrikeOutAs Byte lfCharSetAs Byte lfOutPrecisionAs Byte lfClipPrecisionAs Byte lfQualityAs Byte lfPitchAndFamilyAs Byte lfFaceNameAs String * 20 End Type Dim MyFontAs LOGFONT Const OutString = "测试哈文字yingyu 123" Const X = 100 Const Y = 400
Private Sub Command1_Click() Dim hFontAs Long Dim hOldFontAs Long hFont = CreateFontIndirect(MyFont)'建立逻辑字体 hOldFont = SelectObject(Me.hdc, hFont)'选入设备环境 TextOut Me.hdc, X, Y, OutString, Len(OutString) '输出逻辑字体 hFont = SelectObject(Me.hdc, hOldFont)'恢复设备环境 DeleteObject hFont
End Sub
Private Sub Form_Load() Dim AngleAs Integer Angle = 90 '输出角度 MyFont.lfHeight = 18 'MyFont.lfWidth=0 MyFont.lfEscapement = Angle * 10 'MyFont.lfWeight=FW_NORMAL 'MyFont.lfCharSet=ANSI_CHARSET 'MyFont.lfPitchAndFamily=FF_MODERN 'MyFont.lfQuality=PROOF_QUALITY End Sub