Answer the question
In order to leave comments, you need to log in
PictureBox keeps empty?
Does not save what is drawn in the picturebox I draw like
this
Graphics g = pictureBox1.CreateGraphics();
Pen a = new Pen(Color.Red, 6);
g.DrawRectangle(a, 100, 100, 50, 100);
Bitmap bm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(bm, new Rectangle(0, 0, bm.Width, bm.Height));
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
bm.Save(sfd.FileName);
}
Answer the question
In order to leave comments, you need to log in
int w = 200; int h = 200;
pictureBox1.Width = w;
pictureBox1.Height = h;
pictureBox1.Image = new Bitmap(w, h);
Pen a = new Pen(Color.Red, 6);
using (Graphics g = Graphics.FromImage(bm))
{
g.FillRectangle(new SolidBrush(Color.White), 0, 0, w, h); // Let the white background be
g.DrawRectangle(a, 100, 100, 50, 100); // Red rectangle
}
if (sfd.ShowDialog() == DialogResult.OK)
pictureBox1.Image.Save(sfd.FileName);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question