以编程方式按钮触发?

时间:2015-03-11 08:21:47

标签: c# button

因此,我尝试按下按钮,以便在点击按钮时,按钮将变为透明,并在后台开始游戏。我是新人,不知道我在做什么,但这是我的代码:

public Form1()
        {
            //Just ignore all this

            InitializeComponent();

            Label[] labelArray = { label1, label2, label3, label4, label5,
            label6, label7, label8, label9 };

            for (int i = 0; i < labelArray.Length; i++)
            {
                labelArray[i].BackColor = System.Drawing.Color.Transparent;
            }

            //Button details...
            Button buttonStart = new Button();

            buttonStart.Location = new Point(90, 150);
            buttonStart.Text = ("Click start to begin");
            buttonStart.Size = new Size(150, 50);

            //Adding the evnet handler
            buttonStart.Click += new EventHandler(buttonStart_Click);

            //Adding the button to the form
            this.Controls.Add(buttonStart);
            buttonStart.BringToFront();

            //Clicking it, in the hopes that what in (buttonStart_Click event
            //handler would do something)

            buttonStart.PerformClick();
        }

        //Eventhandler that says it cannot recoqnize
        //my "buttonStart", and I cannot seem to find any other way to do this

        private void buttonStart_Click(object sender, EventArgs e)
        {
            buttonStart.BackColor = System.Drawing.Color.Transparent;
        }

1 个答案:

答案 0 :(得分:0)

试试这个:

private void buttonStart_Click(object sender, EventArgs e)
        {
            this.buttonStart.visible = false;
        }