的WinForms,使用码头属性时创建填充

编程入门 行业动态 更新时间:2024-10-26 16:22:24
本文介绍了的WinForms,使用码头属性时创建填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我如何使用dockstyle.top属性时添加填充,或文本框之间的一些空间呢?

How do I add padding, or some space between the textboxes when using dockstyle.top property?

for(int i =0; i< 10; i++) { textboxes[i] = new TextBox(); textboxes[i].Dock = DockStyle.Top; mypanel.Controls.Add(textboxes[i]); }

上面的代码把文本框的正下方对方。不使用大规模面板或固定定位不明白这一点。如何做到以下几点?

The code above puts textboxes right beneath each other. Can't figure this out without using mass panels or fixed positioning. How to do the following?

1)我想补充周围框之间10-20pixels。

1) I would like to add around 10-20pixels between boxes.

2)如何改变文本框,尺寸(高度,宽度)在使用dockstyle.top它忽略了大小命令,因为?

2) How to change size (height,width) of the textboxes, since when using dockstyle.top it ignores the size commands ?

推荐答案

通过DockStype.Top你不能改变你的文本框的宽度,因为他们停靠。你只能改变高度。但要改变文本框的高度,你必须设置多=真事先

With DockStype.Top you can't change the width of your TextBoxes, cause they are docked. You can only change the height. But to change the height of a TextBox you have to set the Multiline = true beforehand.

要获得空间你必须把一个小组内的每个文本框不同的框之间,将 TextBox.Dock =填写的 Panel.Dock =顶部和 Panel.Padding = 10 。现在你有每个文本框之间的一些空间。

To get the space between the different boxes you have to put each TextBox within a panel, set the TextBox.Dock = Fill, the Panel.Dock = Top and the Panel.Padding = 10. Now you have some space between each TextBox.

for (int i = 0; i < 10; i++) { var panelTextBox = CreateBorderedTextBox(); this.Controls.Add(panelTextBox); } private Panel CreateBorderedTextBox() { var panel = CreatePanel(); var textBox = CreateTextBox(); panel.Controls.Add(textBox); return panel; } private Panel CreatePanel() { var panel = new Panel(); panel.Dock = DockStyle.Top; panel.Padding = new Padding(5); return panel; } private TextBox CreateTextBox() { var textBox = new TextBox(); textBox.Multiline = true; textBox.Dock = DockStyle.Fill; return textBox; }

我忘了,你也可以给一个尝试到的FlowLayoutPanel 。单从面板中删除 DockStyle.Top ,并把它们放入FlowLayoutPanel的。你也应该设置的FlowDirection 以自上而下的。也许这也可以帮助你解决你的问题了。

What i forgot, you can also give a try to the FlowLayoutPanel. Just remove the DockStyle.Top from the panels and put them into the FlowLayoutPanel. Also you should set the FlowDirection to TopDown. Maybe this can also help you to solve your problem, too.

更多推荐

的WinForms,使用码头属性时创建填充

本文发布于:2023-11-05 19:23:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:码头   属性   WinForms

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!