title: Hwo to stop winforms panel from changing the Y coordinate of my added controls when scrolling is used?
body: <p>Here is my code:</p>
  <pre><code>private void btn_creategroup_Click(object sender, EventArgs e)
  {
      ListView listview = new ListView();
      listview.BackColor = normalColor;
      listview.BorderStyle = BorderStyle.Fixed3D;
      listview.ForeColor = System.Drawing.Color.Black;
      listview.Name = &quot;Group&quot; + count2;
      int futureCount = autolayoutGroups.Controls.Count + 1;
      int actualCount = futureCount - 1;
      int spacing = 20;
      int width = (int)(currentWidth / 2) - (spacing + (spacing / 2));
      int height = (int)(currentHeight / 2) - (spacing + (spacing / 2));
      int ycount = 0;
      int xcount = 0;
  
      if (actualCount &gt; 1)
      {
           if (actualCount % 2 == 0)
           {
                globalYCount += 1;
           }
      }
  
      if (actualCount &gt; 1)
      {
           ycount = actualCount / 2;
      }
  
      if (actualCount &gt; 0)
      {
           if (actualCount == 1)
           {
                xcount = 1;
           }
           else
           {
                if (actualCount % 2 == 0)
                {
                      xcount = 0;
                }
                else
                {
                    xcount = 1;
                }
  
            }
      }
  
      listview.Location = new System.Drawing.Point(spacing + (xcount * (width + spacing)), spacing + (ycount * (height + spacing)));
      listview.Size = new System.Drawing.Size(width, height);
  
      autolayoutGroups.Controls.Add(listview);
              
  }
  </code></pre>
  <p>please excuse my bad code I'm a beginner and arrived at this solution through lots of trial and error, when I run my code with autoscroll enabled on the panel and I don't scroll everything works fine, I can add as many listviews as I want and they all lineup fine, but if a scroll any and then add more listviews the Y position of the new list views is off.</p>
  <p>List views created without scrolling:
  <a href="https://i.stack.imgur.com/ayBQC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ayBQC.png" alt="List views created without scrolling" /></a></p>
  <p>ListViews created after scrolling down a little:
  <a href="https://i.stack.imgur.com/krJXl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/krJXl.png" alt="enter image description here" /></a></p>
  <p>I used message boxes to tell me what the calculated Y position was when I created the listviews and then I used a message box and a click function to tell me the actual Y position of the listview control and they don't match.
  How can I fix this?</p>