#318 – TextBox Basics

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);
        }

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: