VB如何把文字打印到屏幕上?
不是VB的print,把文字打印到form窗体中。。。是直接打印文字到windows桌面上~~知道朋友请帮帮忙,谢谢了。一楼和二楼都不是我要达到目的。。。谢谢。本想用Dr...
不是VB的print,把文字打印到form窗体中。。。
是直接打印文字到windows桌面上~~
知道朋友请帮帮忙,谢谢了。
一楼和二楼 都不是我要达到目的。。。谢谢。本想用 DrawText 来完成,但做完了不报错,不过也没有效果。。。
可能我API用错了。。。希望知道的朋友能帮下忙
如图片。。。
必竟你让窗体透明,还会在桌面占用一点空间位置,如果这么打印到屏幕上,一刷新就没了,不影响WINDOWS的任何使用,这样很舒服。 展开
是直接打印文字到windows桌面上~~
知道朋友请帮帮忙,谢谢了。
一楼和二楼 都不是我要达到目的。。。谢谢。本想用 DrawText 来完成,但做完了不报错,不过也没有效果。。。
可能我API用错了。。。希望知道的朋友能帮下忙
如图片。。。
必竟你让窗体透明,还会在桌面占用一点空间位置,如果这么打印到屏幕上,一刷新就没了,不影响WINDOWS的任何使用,这样很舒服。 展开
6个回答
展开全部
VB6.0把文字输出到屏幕需要使用GetDC、ReleaseDC和DrawText等三个API函数实现。
实现代码:
Option Explicit
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DrawText Lib "user32.dll" 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 Sub Command1_Click()
Dim lngDC As Long
Dim rt As RECT
Dim strText As String
strText = "Hello !"
'屏幕打印位置
With rt
.Left = 500
.Top = 200
.Right = 600
.Bottom = 600
End With
lngDC = GetDC(0)
DrawText lngDC, strText, Len(strText), rt, 0
ReleaseDC 0, lngDC
End Sub
展开全部
首先清确认你的VB版本,是VB6.0吧。
VB可以将文字打印在各种容器中,如窗体、图片框中,需要用到print语句,其格式为
容器名.print 字符串常量或变量
当容器名省略时,vb将会在当前窗体上打印字符串。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
VB6.0把文字输出到屏幕需要使用GetDC、ReleaseDC和DrawText等三个API函数实现。
实现代码:
Option Explicit
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DrawText Lib "user32.dll" 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 Sub Command1_Click()
Dim lngDC As Long
Dim rt As RECT
Dim strText As String
strText = "Hello !"
'屏幕打印位置
With rt
.Left = 500
.Top = 200
.Right = 600
.Bottom = 600
End With
lngDC = GetDC(0)
DrawText lngDC, strText, Len(strText), rt, 0
ReleaseDC 0, lngDC
End Sub
实现代码:
Option Explicit
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DrawText Lib "user32.dll" 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 Sub Command1_Click()
Dim lngDC As Long
Dim rt As RECT
Dim strText As String
strText = "Hello !"
'屏幕打印位置
With rt
.Left = 500
.Top = 200
.Right = 600
.Bottom = 600
End With
lngDC = GetDC(0)
DrawText lngDC, strText, Len(strText), rt, 0
ReleaseDC 0, lngDC
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) 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 Sub Form_Load()
Me.AutoRedraw = True
hBitmap = CreateCompatibleBitmap(Me.hdc, 0, 0)
aa = SelectObject(Me.hdc, hBitmap)
DeleteObject aa
Me.Refresh
End Sub
这个可以让窗体透明而控件显示,注意窗体的Borderstyle=0
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 Sub Form_Load()
Me.AutoRedraw = True
hBitmap = CreateCompatibleBitmap(Me.hdc, 0, 0)
aa = SelectObject(Me.hdc, hBitmap)
DeleteObject aa
Me.Refresh
End Sub
这个可以让窗体透明而控件显示,注意窗体的Borderstyle=0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
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 ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Const TRANSPARENT = 1
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click()
Dim hwnd As Long
Dim rt As RECT
Dim dc As Long
hwnd = GetDesktopWindow()
dc = GetWindowDC(hwnd)
SetBkMode dc, TRANSPARENT
GetWindowRect hwnd, rt
TextOut dc, 0, 0, "你好!!!!!!!!!!!!!!!!" & Chr(0), 20
ReleaseDC hwnd, dc
End Sub
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
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 ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Const TRANSPARENT = 1
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click()
Dim hwnd As Long
Dim rt As RECT
Dim dc As Long
hwnd = GetDesktopWindow()
dc = GetWindowDC(hwnd)
SetBkMode dc, TRANSPARENT
GetWindowRect hwnd, rt
TextOut dc, 0, 0, "你好!!!!!!!!!!!!!!!!" & Chr(0), 20
ReleaseDC hwnd, dc
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询