使用微软的方法,可以使用SendMessage和PaintPicture等方法直接将PictureBox的图形发送到打印机,参见微软代码示例(http://support.microsoft.com/default.aspx?scid=kb;EN-US;194580):Step-by-Step Example
Create a Standard EXE project in Visual Basic. Form1 is created by default.
Place two PictureBoxes and three CommandButton controls on Form1. Adjust the size of Picture2 so that it is at least as large as Picture1.
Select Components from the Project menu and check the Microsoft Rich Textbox Control 6.0.
Place a RichTextBox control inside Picture1.
Place the following code in the General Declarations Section of Form1: Option Explicit Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4& ' Draw the window's client area
Private Const PRF_CHILDREN = &H10& ' Draw all visible child
Private Const PRF_OWNED = &H20& ' Draw all owned windows Private Sub Command1_Click()
' Use the .bmp of your choice and make sure to give the full path.
RichTextBox1.OLEObjects.Add , , "c:\windows\triangles.bmp"
End Sub Private Sub Command2_Click()
Dim rv As Long
Picture1.SetFocus ' So that the button doesn't look pressed
Picture2.AutoRedraw = True
rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Picture2.Picture = Picture2.Image
Picture2.AutoRedraw = False
Command1.SetFocus ' Return Focus
End Sub Private Sub Command3_Click()
Printer.PaintPicture Picture2.Picture, 0, 0
Printer.EndDoc
End Sub
Run the project and click Command1, which puts a .bmp file into the RichTextBox. You will see a border around the .bmp. Click elsewhere on the RichTextBox and the border is removed. Type something into the RichTextBox.
Click on Command2, which copies the whole picture into the PictureBox, Picture2.
Click on Command3 to print the whole composite image.
按照上面的测试之后,RichTextBox中的内容并没有打印,打印的只是RichTextBox的一个框,里面的文字和图形都没有打印出来,这个问题急死我了,希望有过此经验的高手帮忙,重谢重谢!!!!
Create a Standard EXE project in Visual Basic. Form1 is created by default.
Place two PictureBoxes and three CommandButton controls on Form1. Adjust the size of Picture2 so that it is at least as large as Picture1.
Select Components from the Project menu and check the Microsoft Rich Textbox Control 6.0.
Place a RichTextBox control inside Picture1.
Place the following code in the General Declarations Section of Form1: Option Explicit Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4& ' Draw the window's client area
Private Const PRF_CHILDREN = &H10& ' Draw all visible child
Private Const PRF_OWNED = &H20& ' Draw all owned windows Private Sub Command1_Click()
' Use the .bmp of your choice and make sure to give the full path.
RichTextBox1.OLEObjects.Add , , "c:\windows\triangles.bmp"
End Sub Private Sub Command2_Click()
Dim rv As Long
Picture1.SetFocus ' So that the button doesn't look pressed
Picture2.AutoRedraw = True
rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Picture2.Picture = Picture2.Image
Picture2.AutoRedraw = False
Command1.SetFocus ' Return Focus
End Sub Private Sub Command3_Click()
Printer.PaintPicture Picture2.Picture, 0, 0
Printer.EndDoc
End Sub
Run the project and click Command1, which puts a .bmp file into the RichTextBox. You will see a border around the .bmp. Click elsewhere on the RichTextBox and the border is removed. Type something into the RichTextBox.
Click on Command2, which copies the whole picture into the PictureBox, Picture2.
Click on Command3 to print the whole composite image.
按照上面的测试之后,RichTextBox中的内容并没有打印,打印的只是RichTextBox的一个框,里面的文字和图形都没有打印出来,这个问题急死我了,希望有过此经验的高手帮忙,重谢重谢!!!!
解决方案 »
- 足足搞了一天,那天的不稳定请各位老师指点
- VB界面设计的问题
- 太久没用VB,生疏了。呵呵,提个控件问题
- 如果把数据控件与msflexgrid控件绑定了后。msflexgrid数据如果更新后。数据控件也更新吧?
- 大侠们,请教一下查询的问题!
- 各位高手请给小弟帮一帮忙,关于sql的问题......................急(满分送出)
- 控件不可用是,怎么显示toolpittext内容呢?
- 在VB下如何用sql语句获得sql server服务中的数据库的名称
- 怎么样在vb程序加入程序入口函数sub main()
- VC能够调用VB编写的ActiveX DLL中的函数吗?
- 关于模式窗体的问题,在线等待!分不够可以再加
- 招vb程序员
http://www.china-askpro.com/msg2/qa05.shtml
先将要打印的内容保存为bmp图片,然后再打印bmp图片,打印bmp图片的话,很简单:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command4_Click()
ShellExecute Me.hwnd, "print", "c:\test.bmp", vbNullString, vbNullString, 1
End Sub
即可