• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Printing bitmaps with RichTextBox

The RichTextBox can display OLE objects and pictures but not print them. How can I print them?
  • 2
1 Solution
You can use the PictureBox PaintPicture method.
mrmick, what does that mean????

The only reasonable way I have found around this problem is to use OLE automation or ShellExecute to print the contents. Not very nice, but works.

An example:

' To forms general section
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

'Eg to a button
Private Sub btnPrint_Click()
    Dim RTFString As Object
    Dim lResult As Long
    ' Creates a file to receive the RTF information from the control.
    Open "C:\RTFText.rtf" For Output As 1
    ' Places the RTF information from the control into the file and
    ' closes the file.
    Print #1, RichTextBox1.TextRTF
    Close 1
    ' Opens the new file in program associated with rtf-extension and prints it.
    lResult = ShellExecute(Me.hwnd, "print", "c:\rtftext.rtf", "", "c:\", 0&)
End Sub

aktisAuthor Commented:
I have a rtf text and inside the text is a picture.
Sorry, I figured that out with rantanen's help... at the first glance, I thought you were using a RichTextBox control to display pictures.  Give rantanen's suggestion a try.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now