How to Determine the Size of the Textbox Using ForEach Loop in VB.Net

0
564

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.

Let’s begin:

Open Visual Basic 2008, create a new Windows Application and drag the TextBox and A Button in a Form.

determinethesize

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. Try
  3. 'FOR EACH TXT AS CONTROL IN THE FORM OF CONTROLS
  4. 'GET THE COLLECTION OF A CONTROL CONTAIN WITHIN THE CONTROL.
  5. For Each txt As Control In Me.Controls
  6. 'CHECKING IF THE TYPE OF A CONTROL WAS A TEXTBOX
  7. If txt.GetType Is GetType(TextBox) Then
  8. 'GET OR SET THE HEIGHT AND WIDTH OF THE TEXTBOX
  9. txt.Text = "SIZE:" & txt.Size.ToString
  10. End If
  11. Next txt
  12. Catch ex As Exception
  13. MsgBox(ex.Message)
  14. End Try

Press F5 to run your project and click the Button to work the code in the method.

Output :
determinethesizeoutput

 

Readers might read also:

 

 

Facebook Comments
(Visited 29 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here