使用文本框的提示Tips on using text boxes

TextBox 是由以下属性控制的灵活控件: Text多行WordWrapAutoSizeThe TextBox is a flexible control governed by the following properties: Text, MultiLine, WordWrap, and AutoSize.

  • Text 包含文本框中显示的文本。Text contains the text that's displayed in the text box.

  • 行控制TextBox是否可以将文本显示为单行或多行。MultiLine controls whether the TextBox can display text as a single line or as multiple lines. 换行符标识一行的结束和另一行的开始。Newline characters identify where one line ends and another begins. 如果多行False, 则文本将被截断而不是换行。If MultiLine is False, the text is truncated instead of wrapped.

  • WordWrap 允许Textbox将超出TextBox宽度的文本行换行到适合的较短行。WordWrap allows the TextBox to wrap lines of text that are longer than the width of the TextBox into shorter lines that fit.

    如果不使用 WordWrapTextBox 只在遇到文本中的换行符时才开始新行。If you do not use WordWrap, the TextBox starts a new line of text when it encounters a newline character in the text. 如果关闭 WordWrap 功能,则可以具有超出 TextBox 宽度的文本行。If WordWrap is turned off, you can have text lines that do not fit completely in the TextBox. TextBox 显示在其宽度内的文本部分,而超出的部分则被截断。The TextBox displays the portions of text that fit inside its width and truncates the portions of text that do not fit. 除非 MultiLineTrue,否则 WordWrap 不可用。WordWrap is not applicable unless MultiLine is True.

  • AutoSize 控制TextBox是否调整以显示所有文本。AutoSize controls whether the TextBox adjusts to display all of the text. AutoSizeTextBox 结合使用时, TextBox 的宽度会根据 TextBox 中的文本量以及用于显示文本的字体缩小或扩大。When using AutoSize with a TextBox, the width of the TextBox shrinks or expands according to the amount of text in the TextBox and the font size used to display the text.

    AutoSize 在以下情况下效果很好:AutoSize works well in the following situations:

    • 显示含一行或多行文本的标题。Displaying a caption of one or more lines.
    • 显示单行 TextBox 的内容。Displaying the contents of a single-line TextBox.
    • 显示对用户只读的多行 TextBox 中的内容。Displaying the contents of a multiline TextBox that is read-only to the user.

备注

避免对已使用 MultiLineWordWrap 属性的空 TextBox 使用 AutoSizeAvoid using AutoSize with an empty TextBox that also uses the MultiLine and WordWrap properties. 在用户在使用这些属性的 TextBox 中输入文本时, TextBox 将自动变成一个细长的框,其宽度为一个字符,长度与文本行相同。When the user enters text into a TextBox with these properties, the TextBox automatically sizes to a long narrow box one character wide and as long as the line of text.

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.