How to Get the X/Y Point of a Textbox Using For Each Loop
Submitted by janobe on Wednesday, April 23, 2014 - 17:52.
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
Run your project and click the Button to start the code in the method.

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
Add new comment
- 39 views