I have a panel and a button that adds text boxes to the panel in the following configuration:
| textbox1 |
| textbox2 |
etc. The vertical width of each textbox is 27 so what I do is keep track of a y-coordinate and add 30 to it every time I make a new textbox, and put the textbox at that y coordinate. The problem is that after a few textboxes a scrollbar appears, and when I add a new textbox, the origin is taken to be at the top left corner of the visible por开发者_如何学Gotion of the panel, not the top left corner of the complete panel. This results in a lot of space between some textboxes. Can anyone help me fix this? Thank you.
I would use a FlowLayoutPanel instead. Then you could just add your textboxes by doing flowLayoutPanel1.Controls.Add(mytextbox1);
The other option is explained in this post.
Another example is Setting position of a control doesn't seem to work when scroll is 'moved'
Hmm... Even if it seems strange to me that origin "shifts", try aftrr that you added last TextBox add your Delta from its Bounds.Bottom which will generate Top of next TextBox to add.
Hope this helps.
Have you considered using a Flowlayout Panel?
http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel.aspx
精彩评论