N
N
NikSIk312019-12-20 01:16:52
JavaScript
NikSIk31, 2019-12-20 01:16:52

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);

I save like this
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);
            }

saves the entire area from the box, just empty with no content

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2019-02-11
@Rsa97

regexp = /^[a-zа-яё0-9\s\-\(\):]$/iu;Extra escapes are not needed.

A
AlexV, 2019-12-20
@Av-IT

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 question

Ask a Question

731 491 924 answers to any question