
private void from1_DoubleClick(object sender, EventArgs e)
{
TextBox mytestbox = new TextBox()
mytestbox.Location = PointToClient(MousePosition)
mytestbox.Size = new Size(100,50)//自己调整
this.Controls.Add(mytestbox)//添加,添到哪里自己调整
}
打开Microsoft Visual Studio 2010新建解决方案,
添加项目——动态生成控件
窗体布局
把窗体设置合适的大小
确定控件的基本属性
1、假设要添加15个button按钮;
2、基本属性如下:
Name:名称 myButton
Text:显示文本 按钮(i)
Size:大小 50*50
Location:窗体位置
Location属性如何动态变化?(分析如图)
假设要把15个按钮,每5个一行生成,那么就需要让Location属性动态变化?怎么办?
经过分析,确定X的坐标为:50+i%5*100
Y的坐标如何动态确定?
1、定义一个行变量;
2、Y的坐标为:50+row*100
3、增加判断换行条件:i % 5 == 0 &&i != 0
输入代码试试看?ok!运行效果如图
if(c
is
Label||c
is
RadioButton)
{
string
Str
=
((Label)c).Text
string
Stt
=
((RadioButton)c).Text
list.Add(Str)
list.Add(Stt)
}
这是有问题啊,得分别判断是label还是RadioButton
然后再添加到list中。而且一次只能循环一个控件也不能一次就能把两中同时都能添加进去啊
应该这样改吧,你参考一下:
if
(c
is
Label)
{
string
Str
=
((Label)c).Text
list.Add(Stt)
}
if
(c
is
RadioButton)
{
string
Stt
=
((RadioButton)c).Text
list.Add(Str)
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)