title: Windows Forms C# draw whole scrollable panel
body: <p>I have a problem with my scrollable panel in Windows Forms C#.</p>
  
  <p><strong>My Situation</strong>
  I have a Form with a tabControl.
  In 1 of the tabs i have a panel that fills the whole tab and is scrollable.
  In runtime i fill this panel with about 60 other panels and 6 pictures in each of the added panels. This leads to 1 big panel that i can scroll down.</p>
  
  <p><strong>My Problem</strong>
  Now drawing 1 of these sub panels takes about 0.2 seconds on my bad pc which is fine and reaosnable but i have the problem that it is only drawing the things that are currently visible in the main panel.
  Even if i let the main panel load for 1 minute he still only draws the first couple of sub panels and if i scroll down he has to draw the rest.
  If i scroll up again everything is smoot, so it looks like it is storing everything that was drawn once.
  I would like abehaviour where he basically draws the whole main panel in the beginning and afterwards the scrolling is smooth.</p>
  
  <p>PS: I am not sure if "drawing" is the right word for what the form is doing.
  PPS: I know that this code is not perfect, but I am not complaining about performance issues but I just want to understand how this loading works
  Some code:</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e) {
  
              pnEverything.Controls.Clear();
              int yPosition = 20;
              for (int i = 1; i &lt;= 48; i++) {
                  Panel panel = new Panel();
                  Label label = new Label();
  
                  if (i % 2 != 0) {
                      panel.Location = new Point(10, yPosition);
                  }
                  else {
                      panel.Location = new Point(this.Size.Width / 2 + 10, yPosition);
                      yPosition += this.Size.Width / 10;
                  }
                  panel.Size = new Size(this.Size.Width / 2 - 80, ((this.Size.Width / 2 - 80) - 90) / 6 + 40);
                  panel.Tag = i;
                  panel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  
                  label.AutoSize = true;
                  label.Font = new Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                  label.ForeColor = Color.Black;
                  label.Name = "lbLade" + i;
                  label.Location = new Point(panel.Width / 2 - label.Size.Width / 2, panel.Size.Height - 30);
                  label.Text = i.ToString();
  
                  panel.Controls.Add(label);
  
                  int xPosition = 30;
                  for (int j = 1; j &lt;= 6; j++) {
                      MyPictureBox pb = new MyPictureBox();
  
                      pb.Location = new Point(xPosition, 10);
                      pb.Margin = new Padding(2);
                      pb.Name = "pbLade" + i + "Nummer" + j;
                      pb.Size = new Size((panel.Size.Width - 90) / 6, (panel.Size.Width - 90) / 6);
                      pb.SizeMode = PictureBoxSizeMode.StretchImage;
                      pb.Cursor = System.Windows.Forms.Cursors.Hand;
                      pb.Position.Lade = i;
                      pb.Position.Nummer = j;
  
                      xPosition += pb.Size.Width + 10;
                      pb.ImageLocation = @"Bilder\plus.png";
                      pb.Click += new EventHandler(pbAddCar_Click);
  
                      panel.Controls.Add(pb);
                  }
                  pnEverything.Controls.Add(panel);
              }
          }
  </code></pre>