有个窗体上面有一个"增加按钮"的Bottun  点击按钮后窗体上自己增加10个按钮.而且每个按钮的文本和运行的事件都不同
(用数据库或数组保按钮的名称和事件动作).请问代码怎样实现呀??

解决方案 »

  1.   

    private void btnKind_Click(object sender, EventArgs e)
            {
                string strbtnName = ((Button)sender).Name.ToString();
                switch (strbtnName)
                {
                    case "btnKind1": axMSChart.chartType = MSChart20Lib.VtChChartType.VtChChartType3dLine; break;
                    case "btnKind2": axMSChart.chartType = MSChart20Lib.VtChChartType.VtChChartType2dLine; break;
                    case "btnKind3": axMSChart.chartType = MSChart20Lib.VtChChartType.VtChChartType3dBar; break;
                    case "btnKind4": axMSChart.chartType = MSChart20Lib.VtChChartType.VtChChartType2dBar; break;
                    case "btnKind5": axMSChart.chartType = MSChart20Lib.VtChChartType.VtChChartType2dPie; break;
                    case "btnKind6": axMSChart.chartType = MSChart20Lib.VtChChartType.VtChChartType2dStep; break;
                    case "btnKind7": axMSChart.chartType = MSChart20Lib.VtChChartType.VtChChartType3dStep; break;
                }
            }希望对你有帮助
      

  2.   

    Button[] btns = new Button[9];//点击 按钮
    for ( int i = 0; i<9; i++)
    {
        btns[i] = new Button();
        btns[i].Location = new System.Drawing.Point(100,100);
        btns[i].Name = "";
        btns[i].Size = new System.Drawing.Size(48,48);
        btns[i].Text = i.toString();
        btns[i].Click += new System.EventHandle(this.btns.Click)
        this.Controls.Add(btns[i]);
    }