#318 – TextBox Basics
June 10, 2011 Leave a comment
A TextBox control is a control that displays some text and allows a user to edit it.
The Text property controls that text that is displayed in the TextBox. It can be set, to indicate the text that should appear in the TextBox. It can also be read, to retrieve text entered by the user.
<StackPanel> <TextBox Name="txtKing" Text="I'm Henry VIII." Height="25" Width="150"/> <Button Content="Display Text" Click="Button_Click" Width="100" Margin="10"/> </StackPanel>
When the program starts, the TextBox contains the desired text:
The user can edit this text or enter new text.
private void Button_Click(object sender, RoutedEventArgs e) { MessageBox.Show(txtKing.Text); }