How to Determine the Size of the Textbox Using ForEach Loop

This time, 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. Let’s begin: Open Visual Basic 2008, create a new Windows Application and drag the TextBox and A Button in a Form. firstform Double click the button and do the following code into the method.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. 'FOR EACH TXT AS CONTROL IN THE FORM OF CONTROLS
  3. 'GET THE COLLECTION OF A CONTROL CONTAIN WITHIN THE CONTROL.
  4. For Each txt As Control In Me.Controls
  5. 'CHECKING IF THE TYPE OF A CONTROL WAS A TEXTBOX
  6. If txt.GetType Is GetType(TextBox) Then
  7. 'GET OR SET THE HEIGHT AND WIDTH OF THE TEXTBOX
  8. txt.Text = "SIZE:" & txt.Size.ToString
  9. End If
  10. Next txt
  11. End Sub
Press F5 to run your project and click the Button to work the code in the method. Output : output

Add new comment