的WinForms,使用码头属性时创建填充 [英] Winforms, creating padding when using Dock properties

查看:174
本文介绍了的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,使用码头属性时创建填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆