matts11
Upsell Wizard
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
100 XP
In this tutorial I will teach you how to get X/Y Point of a Textbox Using For Each Loop in Visual Basic 2008. With this you can easily get the location of a specific Textbox. I used the Foreach Loop so that you don’t have to specify what is the name of your Textbox. All you have to do, is to get the type of it.
Let’s begin.
Open Visual Basic 2008, create a new Windows Application, drag the Textbox and Button you needed. It will look like this.
After that, double click the button to fire the click
event handler. Then, add the following code to the method created.
Run your project and click the Button to start the code in the method.
Let’s begin.
Open Visual Basic 2008, create a new Windows Application, drag the Textbox and Button you needed. It will look like this.

After that, double click the button to fire the click
event handler. Then, add the following code to the method created.
- Private
Sub
Button1_Click(
ByVal
sender As
System.
Object
, ByVal
e As
System.
EventArgs
)
Handles
Button1.
Click
- 'FOR EACH TXT AS WINDOWS FORMS CONTROL IN THE FORM 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
- 'GETTING THE TYPE OF THE TXT CONTROL.
- If
txt.
GetType
Is
GetType
(
TextBox)
Then
- 'IF THE TYPE OF TXT IS TEXBOX,
- 'THE LOCATION OF A SPECIFIC TEXTBOX WILL EXIST INTO IT.
- txt.
Text
=
txt.
Location
.
ToString
- End
If
- Next
- End
Sub
Run your project and click the Button to start the code in the method.