Problem positioning controls within a panel with autoscroll=true

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I don't know if this is a bug or if I am doing something wrong, but hopefully
somebody could help me.
I have a panel with autoscroll=true, and I am trying to position controls
within it, however they don't position correctly.
According to MS's documentation Panel.Left "Gets or sets the distance, in
pixels, between the left edge of the control and the left edge of its
container's client area."

Here's the sample code for you to reconstruct it real quick.
Essentially its a form with a panel with autoscroll=true,
a textbox of any size outside of the panel,
and a button with the following click event handler.

int x = 0;
int y = 0;

private void button1_Click(object sender, System.EventArgs e)
{
TextBox f = new TextBox();
f.Size = textBox1.Size;
f.Multiline = true;
panel1.Controls.Add(f);
f.Left = x1;
f.Top = y1;
//f.Location = new Point(x1, y1);

x1 += 100;
y1 += 100;
panel1.Refresh();
}

It should draw textboxes diagonally toward the right, with a scrollbar
eventually appearing. However, if you move the horiz/vert. scrollbars any
bit after creating a few of these diagonal boxes, it jumps a huge gap, then
creates the textbox. What I think should be happening is that it should
create a lot of textboxes diagonally with no gaps between them regardless of
whether or not the scrollbars have been moved at all. I have tried using the
commented out location line above and I have tried setting the positions
before adding it into the panel. Nothing has worked for me so far.

Thanks
 
Back
Top