How Can I Get The X,Y Position Of A Control In A Form?

md110

Member
Joined
Oct 14, 2008
Messages
11
Programming Experience
1-3
please help me
How Can I Get The X,Y Position Of A Control In A Form?
 
Hi,

Let us take a button control as an example.

then,

dim xPos as Integer
dim yPos as Integer
xPos=button1.Location.X
yPos=button1.Location.Y


Thanks
Panna
 
The same results can be achieved with the control's Left and Top properties:

VB.NET:
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim xPos, yPos As Integer
		Dim lt, tp As Integer
		xPos = Button1.Location.X
		yPos = Button1.Location.Y
		lt = Button1.Left
		tp = Button1.Top
		MessageBox.Show("Left = " & lt & "  Top = " & tp, "X = " & xPos & "  Y = " & yPos)
	End Sub
 
A way for you to find out how to find this information is to search help for Control class and look through its members, logically what you're asking about here is one or more property members so you can click 'Properties' to filter the list to only show those, which lead you to this page: Control Properties (System.Windows.Forms)
By reading the property names and perhaps also their short description, or even reading the dedicated help page for each property if you need to, you should not have too much trouble finding out things like this for yourself.
 
Back
Top