将文本框添加到面板中,文本框之间不留空间
我有一个面板和一个按钮,可按以下配置将文本框添加到面板中:
|文本框1 |
|文本框2 |
ETC。 每个文本框的垂直宽度是 27,所以我所做的就是跟踪 y 坐标,并在每次创建新文本框时向其添加 30,并将文本框放在该 y 坐标处。问题是,在几个文本框之后出现滚动条,当我添加新文本框时,原点被视为位于面板可见部分的左上角,而不是整个面板的左上角。这会导致一些文本框之间产生大量空间。谁能帮我解决这个问题吗?谢谢。
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 portion 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用 FlowLayoutPanel 代替。然后,您可以通过执行
flowLayoutPanel1.Controls.Add(mytextbox1);
添加文本框。另一个选项在 这篇文章。
另一个例子是 当滚动“移动”时,设置控件的位置似乎不起作用
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'
嗯...即使我觉得原点“转移”很奇怪,请尝试在您添加的最后一个 TextBox 后添加您的 Delta 从其 Bounds.Bottom 中,这将生成要添加的下一个 TextBox 的顶部。
希望这有帮助。
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.
您是否考虑过使用 Flowlayout 面板?
http://msdn.microsoft.com/en-us /library/system.windows.forms.flowlayoutpanel.aspx
Have you considered using a Flowlayout Panel?
http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel.aspx