WIN10 series: C # App Control Basics 9

Source: Internet
Author: User

TextBox control

The TextBox control has been touched more or less in the previous article. A TextBox control is a common and easy-to-grasp text editing control that not only receives input data, but can also be used to display text just like the TextBlock control, which is described later in the TextBlock control.

In a XAML file, the use of a TextBox control is as follows:

<textbox?.../>

The following describes the common properties of a TextBox control:

    • Gets or sets the height of the TextBox control.
    • The Width property, Gets or sets the size of the TextBox control.
    • The Text property, gets or sets the textual content that the TextBox control displays.
    • Margin property, Gets or sets the position of the TextBox control.
    • The MaxLength property, Gets or sets the maximum character length that the user is allowed to enter.
    • The Name property, Gets or sets the TextBox control names.
    • The IsReadOnly property gets or sets whether the content displayed by the TextBox control can be modified. A property value of TRUE indicates that the TextBox control displays read-only, does not support editing, and the default value is False, which means that the TextBox control supports editing.

After describing the common properties, take a look at the common events of the TextBox control:

    • The SelectionChanged event, which is triggered when the text selected in the TextBox control has changed.
    • The TextChanged event that is triggered when the text content in a TextBox control changes.

A simple example is followed to illustrate how the Texbox control is used .

Create a new Windows store blank application project and name Textboxdemo to add the following code to the grid element of the MainPage.xaml file.

<!-- Text boxes that have text and can be edited -

<textbox name= "Readwritetextbox" text= " has text and can be edited "horizontalalignment=" left "margin=" 50,72,0,660 "height=" "width= " "/>"

<!-- Text boxes that have text and are not editable -

<textbox name= "ReadOnlyTextBox" text= " non-editable text "isreadonly=" True "horizontalalignment=" left "margin=" 270,72,0,660 "height=" "width="/> "

<!-- text boxes that are text-free and editable -

<textbox name= "Writetextbox" isreadonly= "False" horizontalalignment= "left" margin= "490,72,0,660" Height= "35" Width= "/>"

In the above code, three Texbox text boxes are added, and the text property value of the first text box is "text and editable", indicating that the text box is content and editable at run time. Then define the value of the IsReadOnly property of the second text box to true and set the Text property value to " non-editable text ", which means that this text box is not editable. The IsReadOnly property value of the last text box is defined to false and the Text property is not set, which means that it is text-free but editable.

After you run the program, you can see that the first text box has text and can be edited in the text box, the second text box has text but cannot be edited, the third text box has no text but can be edited, and then enter a text box in the third text box, as shown in effect 4-17.

Figure 4-17 The use of a TextBox control

WIN10 series: C # App Control Basics 9

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.