使用微软的方法,可以使用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的一个框,里面的文字和图形都没有打印出来,这个问题急死我了,希望有过此经验的高手帮忙,重谢重谢!!!!

解决方案 »

  1.   

    用me.printform 试试看能打印出来不
      

  2.   

    呵呵,代码应该没有什么问题,因为我将richtextbox换成textbox控件的话,可以正常打印,我估计richtextbox内部可能进行了什么处理,想把picturebox和它上面的richtextbox一起打印出来的话,可以参考:
    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
    即可