TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET TextBox Example

Use the TextBox control. Access the Text property and the TextChanged event handler.
TextBox. Users often need to enter text into programs. The TextBox control in Windows Forms is the simplest way to implement this capability. With its Text property, and its TextChanged event, we have a powerful and easy-to-use input control.
To start, please open a new VB.NET Windows Forms project in Visual Studio. Open the Toolbox window from the View menu. Then, drag a TextBox control onto the window of your project.

Next: The TextBox will appear on your form. Open the Properties panel and click on the lightning bolt icon.

Events: The lightning bolt will show you events that you can add. Double-click on the TextChanged event.

A TextChanged event will be automatically inserted into your VB.NET code. Here you can add statements that do whatever you want. This code is triggered whenever a character is typed (or deleted) from the TextBox.

Also: If another part of the code changes the text of a TextBox, TextChanged will also be triggered.

Method that handles TextChanged event: VB.NET Public Class Form1 Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged ' Get TextBox reference from sender object. ' ... The TextBox1 could be used directly instead. Dim t As TextBox = sender ' Assign the window's title to the Text of the TextBox. ' ... This is a string value. Me.Text = t.Text End Sub End Class
We cast the sender Object to a TextBox reference. You could use the TextBox1 directly in your code, but this is often less flexible. We access the Text property on the TextBox. We mirror the Text to the Window title.

Tip: This example does nothing useful, but it shows some important principles of using TextBox.

Text: We almost always use the Text property on TextBox. And TextChanged tends to lead to clearer program logic.

Property
Summary. A text box is used in almost all Windows Forms programs. It provides no formatting support (RichTextBox should be used when formatting is needed). But its simplicity is a benefit. It is easy and clear to use.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf