开发者

C# equivalent to Objective-C's addSubview

Does C# (WinForms) support adding a view or control to another开发者_运维技巧 control? Could anyone give me an example? Thanks in advance.

I use this code in Objective-C.

[aView addSubview:anotherView];


You can do this programatically with a Panel.

You could also use Visual Studio's Designer GUI to create a UserControl, which is more reusable, since you will be able to drag and drop it on to any form at design time.

Sorry if I misunderstand the question.

public Form1()
{
    InitializeComponent();

    Panel p = new Panel()
    {
        BackColor = Color.PowderBlue,
        Location = new Point(10, 10)
    };

    p.Controls.Add(new Label()
        {
            Text = "Hello",
            BackColor = Color.PaleGreen,
            Location = new Point(20, 20)
        });

    p.Controls.Add(new Button()
        {
            Text = "Woof",
            BackColor = Color.Orchid,
            Location = new Point(60, 60)
        });

    this.Controls.Add(p);
}

alt text http://img214.imageshack.us/img214/5861/captureek.png

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜