title: How to prevent Windows forms' new MDI from clearing my graphics from my previous MDI?
body: <p>I have created this application as shown in the image below.</p>
  
  <p><a href="https://i.stack.imgur.com/Yvu3Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yvu3Q.png" alt="enter image description here"></a></p>
  
  <p>Now if I move my right window a bit to left as seen in this picture down below,</p>
  
  <p><a href="https://i.stack.imgur.com/SVWP5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SVWP5.png" alt="enter image description here"></a></p>
  
  <p>My first(or the one at the left) MDI window's graphics are gone as shown below. </p>
  
  <p><a href="https://i.stack.imgur.com/cWc7Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cWc7Y.png" alt="enter image description here"></a></p>
  
  <p>In fact, whenever I minimize my form, the contents of both the windows are gone. I am using graphics object to drawn on the panel. Here is the code for my child form. The main form just has a menu file which has a submenu called new which basically open this child form. </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace MDITest
  {
      public partial class EnhancedPainter : Form
      {
          bool paint = false;
          string color = "Red";
          int size = 5;
  
          public EnhancedPainter()
          {
              InitializeComponent();
          }
  
          private void panel1_MouseDown(object sender, MouseEventArgs e)
          {
              paint = true;
          }
  
          private void panel1_MouseUp(object sender, MouseEventArgs e)
          {
              paint = false;
          }
  
          private void panel1_MouseMove(object sender, MouseEventArgs e)
          {
              if (paint)
              {
                  Graphics g = panel1.CreateGraphics();
                  g.FillEllipse(new SolidBrush(Color.FromName(color)), e.X, e.Y, size, size);
                  //g.Dispose();
              }
          }
  
          private void redRadioButton_CheckedChanged(object sender, EventArgs e)
          {
              color = "Red";
          }
  
          private void greenRadioButton_CheckedChanged(object sender, EventArgs e)
          {
              color = "Green";
          }
  
          private void blueRadioButton_CheckedChanged(object sender, EventArgs e)
          {
              color = "Blue";
          }
  
          private void blackRadioButton_CheckedChanged(object sender, EventArgs e)
          {
              color = "Black";
          }
  
          private void smallRadioButton_CheckedChanged(object sender, EventArgs e)
          {
              size = 5;
          }
  
          private void mediumRadioButton_CheckedChanged(object sender, EventArgs e)
          {
              size = 10;
          }
  
          private void largeRadioButton_CheckedChanged(object sender, EventArgs e)
          {
              size = 15;
          }
  
          private void resetButton_Click(object sender, EventArgs e)
          {
              Graphics g = panel1.CreateGraphics();
              g.FillRectangle(new SolidBrush(Color.White), 0, 0, panel1.Width, panel1.Height);
              g.Dispose();
          }
  
  
      }
  }
  </code></pre>
  
  <p>So how do I prevent this from happening?</p>
  
  <p>Thanks</p>