雖然不是很清楚您的需求......
我假設您是想動態增加元件(例如:Button)到對應的容器中(pictureBox1, groupBox1), 然後您希望透過傳遞一個參數來動態建立原件到參數所指定的容器中......
底下這段您看看有沒有符合需求:- private void button1_Click(object sender, EventArgs e)
- {
- AddControl(20, 20, 100, 20, pictureBox1); //pictureBox1中加button
- AddControl(20, 20, 100, 20, groupBox1); //groupBox1中加button
- }
- void AddControl(int x, int y, int w, int h, Control control)
- {
- Button bt = new Button();
- bt.SetBounds(x, y, w, h);
-
- bt.Parent = control;
- }
複製代碼 ... |