C#如何动态创建控件?在winform中怎么使用代码来创建控件并添加控件事件啊?
另外这段代码有没有更好的写法?我想让控件在窗口中排成一个3*3的格式 程序代码:
private void 布局() { Button[] bu = { button1, button2, button3, button4,button5,button6,button7,button8,button9}; foreach (Button but in bu) { but.Top = 0; but.Left = 0; but.Height = 100; but.Width = 100; but.Cursor = Cursors.Hand; } for (int i = 0; i < 3;i++ ) { bu[i].Left = i<=0?0:bu[i-1].Left+bu[i].Width; } for (int i = 3; i < 6;i++ ) { bu[i].Top = bu[i].Height; bu[i].Left = i <= 3 ? 0 : bu[i - 1].Left+bu[i].Width; } for (int i = 6; i < 9;i++ ) { bu[i].Top = bu[i].Height * 2; bu[i].Left = i <= 6 ? 0 : bu[i - 1].Left+bu[i].Width; } }如果我要使用代码来创建的话要怎么写啊?