This tutorial is all about How to Determine the Size of the Textbox Using ForEach Loop in VB.Net.
In this tutorial I will teach you how to determine the size of the TextBox by using ForEach Loop in Visual Basic 2008. With this, it will be easy for you to determine what will be the sizes of the TextBox without specifying each of it. And the sizes will automatically appear in each Textboxes.
Open Visual Basic 2008, create a new Windows Application and drag the TextBox and A Button in a Form.
Double click the button and do the following code into the method.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
‘FOR EACH TXT AS CONTROL IN THE FORM OF CONTROLS
‘GET THE COLLECTION OF A CONTROL CONTAIN WITHIN THE CONTROL.
For Each txt As Control In Me.Controls
‘CHECKING IF THE TYPE OF A CONTROL WAS A TEXTBOX
If txt.GetType Is GetType(TextBox) Then
‘GET OR SET THE HEIGHT AND WIDTH OF THE TEXTBOX
txt.Text = “SIZE:” & txt.Size.ToString
Catch ex As Exception
Press F5 to run your project and click the Button to work the code in the method.
Readers might read also:
- How to Display and Count the Total Value of the Records in the DataGridView Using Visual Basic 2008
- How to Get the X and Y Point of the TextBox Using For Each Loop in VB.Net