April 14th, 2011, 05:08 AM
problem with pictureBox
I spent the last two days strugling to make this work and i rly cant find what is wrong.
My application is used to draw something in a picturebox and then print it in with a printer.
However the problematic part is the drawing part so i've built this example program for you to see:
In a form i use two pictureBoxes , one textbox and two buttons ( one that is used to draw the text of the textbox on the picturebox, and a second one to "wipe" everything).
The first picturebox has an image i paint in microsoft paint.
The idea is to use the second picturebox to copy the image of the first picturebox on it and THEN draw the text on it too.
I want the first picturebox to remain untouched so to use it as a backup for my paint image and when i use the "wipe" button, to clear the second picturebox and copying the paint image on it again which appears on the first picturebox.
Heres my code:
private void buttonWipe_Click(object sender, EventArgs e)
pictureBox2.Image = pictureBox1.Image;
private void buttonWrite_Click(object sender, EventArgs e)
using (Graphics g = Graphics.FromImage(pictureBox2.Image))
using (SolidBrush myBrush = new SolidBrush(Color.Black))
using (Font myFont = new Font("Times New Roman", 22, FontStyle.Bold))
g.DrawString(textBox1.Text, myFont, myBrush, 12, 52);
Note: When the program starts pictureBox2.Image also is set to the same image as pictureBox1.
The result of this:
1)When you type something in the textbox and click on Write button, it works fine and draws the text on the picturebox.
2) If u then click on the wipe button the result is the one that i wish, the text disappears from picturebox2 and only the "background" image i painted can be seen.
3) -Heres where the problems start- If i type something else in the textbox and reclick on the Write button, the old text reappears ont he picturebox together with the new text written on the old one.
4) If u type something else and click on the writte button again, it will just add a new text above all of the previous text messages. !note that the "Wipe" button has stoped working after the first time.
Anyone knows how to sort that?
Thanks in advance!
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.