110,536
社区成员
发帖
与我相关
我的任务
分享
System.Windows.Forms.Form fm1 = new System.Windows.Forms.Form();
System.Windows.Forms.TextBox txtbox1 = new System.Windows.Forms.TextBox() { Top=5,Left=5 };
fm1.Controls.Add(txtbox1);
for (int i = 0; i < 10; i++)
{
System.Windows.Forms.Button btnitm = new System.Windows.Forms.Button()
{
Text = i.ToString(),
Top = 5 * 2 + txtbox1.Height + i * (5 + (new Button()).Height),
Left = 5
};
btnitm.Click += ( s,eventargs) => {
txtbox1.Text += ((Control)s).Text;
};
fm1.Controls.Add(btnitm);
}
fm1.Height = 5 * 3 + txtbox1.Height + 11 * (5 + (new Button()).Height)+ (new Button()).Height;
fm1.Show();
这段代码就添加了1-9数字控件,删除和回车作为作业你看要怎么写,其实不止是删除,要有回退和清楚两个按钮,回车到底是换行还是执行任务你自己要确认。