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

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.

  3. In the Name box, type ButtonExample, and then click OK.

A new Windows Forms project opens.

  1. From the Toolbox, drag a Button onto the form.

  2. In the Properties window, change the Text property to read: Display Date and then press ENTER.

  3. In the Properties window, click the drop-down arrow to the right of the ForeColor property, and then click the Custom tab of the dialog box that opens.

  4. Click the red box to apply red font to the text of the button.

  5. In the form, double-click the button to open the Code Editor.

The Code Editor opens in the middle of a method named button1_Click. This is the Click event handler. The code you write here will execute when the button is clicked.

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

    MessageBox.Show("Today is " +

    DateTime.Today.ToLongDateString());

  2. Press F5 to run your program.

  3. The program starts and the form appears. When you click the Button, a message box displays today's date.