I don't know how to repaint my picturebox. This is just a demonstration. The production code is too time consuming to put in the paint event. What I need is a way to capture the image that is drawn in the pucturebox with the graphics methods so I can quickly repaint it when needed.
Here's a demo:
public partial class Form1 : Form
{
Image Outout;
public Form1()
{
InitializeComponent();
button1.Click += Button1_Click;
}
private void Button1_Click(Object sender, EventArgs e)
{
PrintPageEventArgs eOutput;
Graphics g;
string OutputText;
Font PrintFont;
OutputText = "CERTIFICATION";
PrintFont = new Font("Arial", 16, FontStyle.Bold);
g = pictureBox1.CreateGraphics();
eOutput = new PrintPageEventArgs(g, new Rectangle(new Point(25, 25), new Size(new Point(825, 1075))), new Rectangle(new Point(0, 0), new Size(new Point(850, 1100))), new PageSettings());
eOutput.Graphics.DrawString(OutputText, PrintFont, Brushes.Black, 0, 0);
Outout = pictureBox1.Image;
pictureBox1.Paint += PictureBox1_Paint;
}
private void PictureBox1_Paint(object sender, PaintEventArgs e)
{
pictureBox1.Image = Outout;
}
}