when I try to save my image all paint and labels disappear here is my code :
//paint on picture box
bool startPaint = false;
Graphics g;
int? initX = null;
int? initY = null;
bool drawSquare = false;
bool drawRectangle = false;
bool drawCircle = false;
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
startPaint = false;
initX = null;
initY = null;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
startPaint = true;
if (drawSquare)
{
//Use Solid Brush for filling the graphic shapes
SolidBrush sb = new SolidBrush(toolStripButton6.BackColor);
//setting the width and height same for creating square.
//Getting the width and Heigt value from Textbox(txt_ShapeSize)
g.FillRectangle(sb, e.X, e.Y, int.Parse(cmb_PenSize.Text), int.Parse(cmb_PenSize.Text));
//setting startPaint and drawSquare value to false for creating one graphic on one click.
startPaint = false;
drawSquare = false;
}
if (drawRectangle)
{
SolidBrush sb = new SolidBrush(toolStripButton6.BackColor);
//setting the width twice of the height
g.FillRectangle(sb, e.X, e.Y, 2 * int.Parse(cmb_PenSize.Text), int.Parse(cmb_PenSize.Text));
startPaint = false;
drawRectangle = false;
}
if (drawCircle)
{
SolidBrush sb = new SolidBrush(toolStripButton6.BackColor);
g.FillEllipse(sb, e.X, e.Y, int.Parse(cmb_PenSize.Text), int.Parse(cmb_PenSize.Text));
startPaint = false;
drawCircle = false;
}
//Text
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (startPaint)
{
//Setting the Pen BackColor and line Width
Pen p = new Pen(toolStripButton6.BackColor, float.Parse(cmb_PenSize.Text));
//Drawing the line.
g.DrawLine(p, new Point(initX ?? e.X, initY ?? e.Y), new
Point(e.X, e.Y));
initX = e.X;
initY = e.Y;
}
}
private void toolStripButton7_Click(object sender, EventArgs e)
{
ColorDialog c = new ColorDialog();
if (c.ShowDialog() == DialogResult.OK)
{
pictureBox1.BackColor = c.Color;
toolStripButton7.BackColor = c.Color;
}
}
private void toolStripButton8_Click(object sender, EventArgs e)
{
drawSquare = true;
}
private void toolStripButton9_Click(object sender, EventArgs e)
{
drawRectangle = true;
}
private void toolStripButton10_Click(object sender, EventArgs e)
{
drawCircle = true;
}
private void toolStripButton11_Click(object sender, EventArgs e)
{
FontDialog dlg = new FontDialog();
dlg.ShowDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string fontName;
float fontSize;
fontName = dlg.Font.Name;
fontSize = dlg.Font.Size;
MessageBox.Show(fontName + " " + fontSize);
}
}