Insert jpeg into Rich Text Box

juggernot

Well-known member
Joined
Sep 28, 2006
Messages
173
Programming Experience
Beginner
yeah, the title speaks for itself. how is it done?
 
Easiest is to copy the image to clipboard and paste it into RTB.
VB.NET:
[SIZE=2]Clipboard.SetDataObject([/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataObject("Bitmap", Image.FromFile("caffrey.jpg")))
RichTextBox1.Paste()
[/SIZE]
 
Thanks. I've got that working now. For some reason tho, When I print the picture doesn't show up. I'll copy and paste my print code:

VB.NET:
Private Sub MenuItem15_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem15.Click
PrintDialog1.AllowSomePages = True
PrintDialog1.Document = doctoprint
doctoprint.OriginAtMargins = True
Dim result As DialogResult = PrintDialog1.ShowDialog()
' If the result is OK then print the document.
If (result = DialogResult.OK) Then
doctoprint.Print()
End If
End Sub
 
Private WithEvents doctoprint As New Printing.PrintDocument
 
Private Sub document_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles doctoprint.PrintPage
Dim text As String = "In document_PrintPage method."
text = Me.RichTextBox1.Text
e.Graphics.DrawString(text, Me.RichTextBox1.Font, _
System.Drawing.Brushes.Black, 10, 10)
End Sub
I think my probelm is that I'm only telling it to draw the text, and not the image. However, I don't know how to properly draw the image, as it should be included in the me.richtextbox1
 
Last edited by a moderator:

Latest posts

Back
Top