如何使自动调节控制? [英] how to make auto adjustable controls?

查看:152
本文介绍了如何使自动调节控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们动态地将控件添加到网页,它的位置是自动调整,一个控制不会将通过另一个。 我们可以做Windows窗体应用程序相同。   我必须在最后一个现有赢得形式添加动态标签,文本框和按钮。

As we dynamically add controls to a web page, its location is automatically adjusted, one control will not place over another. Can we do the same in windows Form Application. I have to add dynamic label, textbox and buttons at last of an existing win form.

推荐答案

看看的的 FlowLayoutPanel的控制。

再presents一个面板,动态水平或垂直方向,勾画出它的内容。

Represents a panel that dynamically lays out its contents horizontally or vertically.

当你掉在 FlowLayoutPanel的,很会照顾自动间隔从另一个控制。如果停靠到形式,使得它与所述形式调整大小,那么它也将处理移动控制,以根据需要下一行/列,这样它们就不会成为隐藏之外的形式的边界

When you drop controls on the FlowLayoutPanel, it will take care of automatically spacing one from another. If you dock it to the form, such that it resizes with the form, then it will also handle moving controls to the next row / column as needed, so they don't become hidden beyond the boundaries of the form.

如果你想将一些控制起来,把他们一个面板里面,然后用它里面的 FlowLayoutPanel的 。下面是一些code证明:

If you want to group some controls together, place them inside a Panel and then use that inside the FlowLayoutPanel. Here's some code to demonstrate:

for (var i = 0; i < 5; i++)
{
    var panel = new Panel { BorderStyle = BorderStyle.FixedSingle, Width = 100, BackColor = Color.LightBlue };

    panel.Controls.AddRange(
        new Control[]
    {
        new Label { Text = "Title", Location = new Point(0, 0) },
        new Label { Text = "Subtitle", Location = new Point(0, 25) }
    });

    flowLayoutPanel1.Controls.Add(panel);
}

这篇关于如何使自动调节控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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