logo
Учебник_ПОА

To use buttons in a program

  1. On the File menu, click NewProject.

  2. In the New Project dialog box, in the Templates pane, click Windows Forms Application, and then click OK.

A new Windows Forms project opens.

  1. From the Toolbox, drag two Button controls onto the form.

  2. In the form, double-click the first button (button1) to create the Click event handler.

  3. In the button1_Click event handler, type the following line of code.

    MessageBox.Show("button1.Click was raised.");

  4. Right-click the code, and then click View Designer.

  5. Double-click the second button (button2) to create the Click event handler.

  6. In the button2_Click event handler, type the following line of code.

    // Call the Click event of button1.

    test.PerformClick();

  7. Press F5 to run the program.

  8. The program starts and the form appears. When you click either button1 or button2, the click event handler of button1 displays a message.