在运行时将控件添加到c#用户控件 [英] Add controls to a c# user control at runtime

查看:67
本文介绍了在运行时将控件添加到c#用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我开发了一个C#用户控件.
在该控件中,我有一个按钮.当用户在运行时单击按钮时,将创建一个新控件(例如pictureBox),该控件位于上一个pictureBox的旁边.

我该怎么做?特别是当我不知道用户要添加多少个PictureBox时(他要按下按钮多少次).

谢谢

Hello,

I develop a c# user control.
In that control, I have a button. When the user clicks the button at runtime, a new control (for example, pictureBox) is created ,next to the previous pictureBox.

How can I do it? especially when I don''t know how many pictureBoxes the user is going to add (how many time is he going to press the button).

Thanks

推荐答案

尝试:
PictureBox pb = new PictureBox();
pb.Location = new Point(oldPb.X, oldPb.Y + 100);
pb.Size = oldPb.Size;
Controls.Add(pb);


这篇关于在运行时将控件添加到c#用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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