There is a youtube post that shows how to make Text from a RichTextBox drawn on top of a PictureBox. The
original code and form includes a Font selector button, and a Color selector button. As you type in text it draws the current text onto the PictureBox. The original tutorial can be found here:
http://www.youtube.com/watch?v=4SbhYg_iwKk
However after you try the code listed in the youtube video, I want to mention the updated code that I used
to add a "Browse" button, and to also make it so you can draw the RichTextBox text over the PictureBox with the PictureBox.Image property already set. This way you actually get your RichTextBox Text opaquely drawn over an actual image of your choice.
All you have to change on your original form, is add a 3rd button, that you can call Browse, set the RichTextBox.Image property to an image of your choice, and then just replace all the original code with this:
original code and form includes a Font selector button, and a Color selector button. As you type in text it draws the current text onto the PictureBox. The original tutorial can be found here:
http://www.youtube.com/watch?v=4SbhYg_iwKk
However after you try the code listed in the youtube video, I want to mention the updated code that I used
to add a "Browse" button, and to also make it so you can draw the RichTextBox text over the PictureBox with the PictureBox.Image property already set. This way you actually get your RichTextBox Text opaquely drawn over an actual image of your choice.
All you have to change on your original form, is add a 3rd button, that you can call Browse, set the RichTextBox.Image property to an image of your choice, and then just replace all the original code with this:
Code:
Public Class Form1
Dim Graph As Graphics
Dim mybasebitmap As Bitmap
Dim my2layerbitmap As Bitmap
Dim Brush As New Drawing.SolidBrush(Color.Black)
Dim mybasebitmapisNull As Boolean = True
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
If (mybasebitmapisNull = True) Then
mybasebitmap = PictureBox1.Image
mybasebitmapisNull = False
End If
my2layerbitmap = New Bitmap(mybasebitmap.Width, mybasebitmap.Height)
Graph = Graphics.FromImage(my2layerbitmap)
Graph.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
Graph.DrawImage(mybasebitmap, RichTextBox1.Location)
Graph.DrawString(RichTextBox1.Text, RichTextBox1.Font, Brush, RichTextBox1.Location)
my2layerbitmap.Equals(Graph)
PictureBox1.Image = my2layerbitmap
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dlg As New FontDialog
If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
RichTextBox1.Font = dlg.Font
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim dlg As New ColorDialog
If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Brush.Color = dlg.Color
RichTextBox1.ForeColor = dlg.Color
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim OpenFile1 As New OpenFileDialog
OpenFile1.Filter = "txt Files (Text Files)|*.txt"
OpenFile1.Title = "Open a Document."
If (OpenFile1.ShowDialog = System.Windows.Forms.DialogResult.OK) Then
RichTextBox1.LoadFile(OpenFile1.FileName, RichTextBoxStreamType.PlainText)
End If
End Sub
Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
End Class