0

For a litte project, I tryed creating a ""Paint App".

Now I want to save the painting as File, sadly, my Method will only save the Background and my menuestrip.

This is how I create the Panel and drawing method:

    private void panel1_Paint(object sender, PaintEventArgs e)  //Bild erstellen
    {
        Graphics g = panel1.CreateGraphics();

        Pen pen = new Pen(colorDialog1.Color);
        g.DrawEllipse(pen, pointx, pointy, width, height);
    }

    private void panel1_MouseMove(object sender, MouseEventArgs e) //Linie malen
    {
        if (e.Button == MouseButtons.Left)
        {
            pointx = e.X;
            pointy = e.Y;
            panel1_Paint(this, null);
        }
    }

This is how I create a Bmp:

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SaveFileDialog save = new SaveFileDialog();
        save.CheckFileExists = false;
        save.CheckPathExists = true;
        save.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
        save.InitialDirectory = @"C:\Users\";

        DialogResult result = save.ShowDialog();
        if (result == DialogResult.OK)
        {
            Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);

            panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height));

            bmp.Save(save.FileName);

        }
    }

My output File looks like:

What is should look like:

Thankful for every advice :)

Eileen
  • 3
  • 7
  • _Graphics g = panel1.CreateGraphics();_ __Never__ use this. Always use `e.Graphics`from the `Paint` parms. Also: You need to collect the locatins in a `List points` and use ` `e.Graphics.DrawLines` or `e.Graphics.DrawCurve(points.ToArray())` ! – TaW Jun 12 '18 at 13:31
  • And for nicer results collect the curve in a `ListPoint>>`[See here](https://stackoverflow.com/questions/31988079/copying-free-hand-drawing-from-panel-in-visual-studio-2013/32112426#32112426) ! For even more advanced doodling [see here](https://stackoverflow.com/questions/49290951/creating-different-brush-patterns-in-c-sharp/49298313#49298313) – TaW Jun 12 '18 at 13:37
  • So I have to rewrite my creation method :D I'll try, thanks @TaW – Eileen Jun 12 '18 at 13:43
  • Well, the saveToolStripMenuItem_Click looks fine; just the others must be overhauled. – TaW Jun 12 '18 at 13:54
  • :D at least someting is right, and thanks a lot for the detailed description in your link! – Eileen Jun 12 '18 at 13:58

0 Answers0