This tutorial is all about How to Get the X and Y Point of the TextBox Using For Each Loop in VB.Net.
In this tutorial I will teach you how to get X/Y Point of a Textbox Using For Each Loop in VB.Net. This method is used to get the location of a specific Textbox and I used the Foreach Loop so that, you don’t need to specify the names of it. All you have to do, is to get it’s type.
Open the Visual Basic, create a new Windows Form Application, drag the Textbox and Button you needed. Set up the Form just like this.
After setting up the Form, double click the Button to fire the
click event handler of it. Then, add the following code to the method created.
[vbnet] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
‘LOOP THE CONTROL ON THE FORM OF CONTROLS
‘ME IS AN OBJECT THAT STANDS AS A FORM
‘CONTROLS ARE BASE CLASS WHICH ARE COMPONENT WITH VISUAL REPRESENTATION
For Each txt As System.Windows.Forms.Control In Me.Controls
‘SET THE TYPE OF THE CONTROL TO A TEXTBOX.
If txt.GetType Is GetType(TextBox) Then
‘GETTING THE LOCATION OF A SPECIFIC TEXTBOX AND WILL APPEAR INTO IT.
txt.Text = txt.Location.ToString
Run your project and click the Button to start the code in the method.
Readers might read also: