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

How to: Use TextBox Controls to Get User Input

You can both display text and retrieve text from users by using a TextBox control. After a user types data in a TextBox, you can retrieve this data by using the Text property. By default, the Multiline property of the TextBox is set to false. This means that users cannot press the ENTER key to create multiple lines of text in the TextBox. You can set the Multiline property to true to enable this.

  1. Добавьте в форму другой элемент управления Button и измените следующие свойства.

    Свойство

    Значение

    Имя

    changeColor

    Текст

    Изменить цвет

    Размер

    80, 23

  2. Дважды щелкните кнопку, чтобы создать обработчик событий changeColor_Click, и добавьте следующий код.

    Random randomColor = new Random();

    this.label1.ForeColor = Color.FromArgb(randomColor.Next(0, 256),

    randomColor.Next(0, 256), randomColor.Next(0, 256));

  3. Нажмите клавишу F5 для выполнения программы.

  4. Нажмите кнопку Изменить текст и убедитесь, что текст в надписи обновлен.

  5. Нажмите кнопку Изменить цвет и убедитесь, изменился цвет шрифта текста.