Assembly : System.Windows.Forms (dans system.windows.forms.dll)
Syntaxe<ComVisibleAttribute(True)> _ <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ Public Class TextBox Inherits TextBoxBase
Dim instance As TextBox
[ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] public class TextBox : TextBoxBase
[ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] public ref class TextBox : public TextBoxBase
/** @attribute ComVisibleAttribute(true) */ /** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ public class TextBox extends TextBoxBase
ComVisibleAttribute(true) ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) public class TextBox extends TextBoxBase
NotesAvec le contrôle TextBox, l'utilisateur peut entrer du texte dans une application. Il a été enrichi de fonctionnalités absentes du contrôle zone de texte Windows standard, dont la modification multiligne et le masquage de caractères d'un mot de passe.
Généralement, un contrôle TextBox n'affiche ou n'accepte en entrée qu'une seule ligne de texte. Les propriétés Multiline et ScrollBars permettent d'activer l'affichage ou l'entrée de plusieurs lignes de texte. Affectez true aux propriétés AcceptsTab et AcceptsReturn pour augmenter les possibilités de manipulation de texte dans un contrôle TextBox multiligne.
Pour limiter la longueur du texte entré dans un contrôle TextBox, affectez à la propriété MaxLength une valeur correspondant à un nombre spécifique de caractères. Les contrôles TextBox peuvent également être utilisés pour accepter des mots de passe et autres informations sensibles. Il est possible d'utiliser la propriété PasswordChar pour masquer des caractères entrés dans une version sur une ligne du contrôle. Utilisez la propriété CharacterCasing pour permettre à l'utilisateur de taper uniquement des majuscules, des minuscules ou une combinaison de majuscules et de minuscules dans le contrôle TextBox.
Pour empêcher l'utilisateur d'entrer du texte dans un contrôle TextBox, vous pouvez créer un gestionnaire d'événements pour l'événement KeyDown, afin de valider chaque caractère entré dans le contrôle. Affecter true à la propriété ReadOnly interdit toute entrée de données dans un contrôle TextBox.
Remarque |
|---|
| La plupart des fonctionnalités du contrôle TextBox sont héritées de la classe TextBoxBase. |
Remarque |
|---|
| Utiliser le contrôle TextBox avec les styles visuels activés entraîne une gestion incorrecte des polices de remplacement. |
Remarque sur la plate-forme Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows CE : Dans les applications Pocket PC, les onglets d'une zone de texte sur une ligne s'affichent sous forme de crochets, mais ils s'affichent normalement lorsque la propriété Multiline a la valeur true.
ExempleL'exemple de code suivant crée un contrôle TextBox multiligne avec des barres de défilement verticales. Il utilise également les propriétés AcceptsTabAcceptsReturn et WordWrap, qui permettent d'utiliser le contrôle zone de texte multiligne lors de la création de documents de texte.
Private Sub CreateMyMultilineTextBox() ' Create an instance of a TextBox control. Dim textBox1 As New TextBox() ' Set the Multiline property to true. textBox1.Multiline = True ' Add vertical scroll bars to the TextBox control. textBox1.ScrollBars = ScrollBars.Vertical ' Allow the RETURN key to be entered in the TextBox control. textBox1.AcceptsReturn = True ' Allow the TAB key to be entered in the TextBox control. textBox1.AcceptsTab = True ' Set WordWrap to True to allow text to wrap to the next line. textBox1.WordWrap = True ' Set the default text of the control. textBox1.Text = "Welcome!" End Sub
private void CreateMyMultilineTextBox() { // Create an instance of a TextBox control. TextBox textBox1 = new TextBox(); // Set the Multiline property to true. textBox1.Multiline = true; // Add vertical scroll bars to the TextBox control. textBox1.ScrollBars = ScrollBars.Vertical; // Allow the RETURN key to be entered in the TextBox control. textBox1.AcceptsReturn = true; // Allow the TAB key to be entered in the TextBox control. textBox1.AcceptsTab = true; // Set WordWrap to True to allow text to wrap to the next line. textBox1.WordWrap = true; // Set the default text of the control. textBox1.Text = "Welcome!"; }
private: void CreateMyMultilineTextBox() { // Create an instance of a TextBox control TextBox^ textBox1 = gcnew TextBox; // Set the Multiline property to true. textBox1->Multiline = true; // Add vertical scroll bars to the TextBox control. textBox1->ScrollBars = ScrollBars::Vertical; // Allow the RETURN key to be entered in the TextBox control. textBox1->AcceptsReturn = true; // Allow the TAB key to be entered in the TextBox control. textBox1->AcceptsTab = true; // Set WordWrap to True to allow text to wrap to the next line. textBox1->WordWrap = true; // Set the default text of the control. textBox1->Text = "Welcome!"; }
private void CreateMyMultilineTextBox() { // Create an instance of a TextBox control. TextBox textBox1 = new TextBox(); // Set the Multiline property to true. textBox1.set_Multiline(true); // Add vertical scroll bars to the TextBox control. textBox1.set_ScrollBars(ScrollBars.Vertical); // Allow the RETURN key to be entered in the TextBox control. textBox1.set_AcceptsReturn(true); // Allow the TAB key to be entered in the TextBox control. textBox1.set_AcceptsTab(true); // Set WordWrap to True to allow text to wrap to the next line. textBox1.set_WordWrap(true); // Set the default text of the control. textBox1.set_Text("Welcome!"); } //CreateMyMultilineTextBox
private function CreateMyMultilineTextBox() { // Create an instance of a TextBox control textBox1 = new TextBox(); // Set the Multiline property to true. textBox1.Multiline = true; // Add vertical scroll bars to the TextBox control. textBox1.ScrollBars = ScrollBars.Vertical; // Allow the RETURN key to be entered in the TextBox control. textBox1.AcceptsReturn = true; // Allow the TAB key to be entered in the TextBox control. textBox1.AcceptsTab = true; // Set WordWrap to True to allow text to wrap to the next line. textBox1.WordWrap = true; // Set the default text of the control. textBox1.Text = "Welcome!"; }
Sécurité des threads
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Remarque
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ