Get absolute position of a control on a form

Seems like an easy question but I've been banging my head all day long..
So:
I have one form which has some controls on it. I can easily get e.g. a textBoxes Location from textBox.Left.

But now I have a datagrid with a few DataGridTextBoxes in it and I need the position of that DataGridTextBox on the Form. I only need to get it, I do not need to manipulate it.

If I call - say .. dataGridTextBox.Left it will give me 0, although that is not correct ...

Is there any method to get the abolsute position of a control on a Form (and not only within it's container)
LVL 4
somnaticAsked:
Who is Participating?
 
TheAvengerCommented:
The DataGridTextBox is probably hidden most of the time, so it actually does not have a correct possition (I suppose). When it's visible, try using Parent property to find the parent control of the current one. Then get its possition and recalculate the position of your control by adding the Left property of the parent to the Left of the current control. Repeat this process until you reach a point where the Parent property is null or a Form and you should have the correct position.
0
 
somnaticAuthor Commented:
well, that's exactely what I tried ..

but the DGTBs Left Property is 0 although there is about 10 -15 pixels space to the left border of the DG.
The same applies to Top Properties.
The Size I get is correct, tho .. but not the location.
0
 
TheAvengerCommented:
Hmm, that's interesting. Have you tried the Bounds property? Or the Location property?
0
 
somnaticAuthor Commented:
I havent tried bounds yet, but Location yields the same results ..
maybe if I find the time, I'll have another go with bounds ...

but I need to finish something else first
0
 
somnaticAuthor Commented:
ok .. i tried bounds .. but still no success ...

probably I'm going to solve it differently .. thanks for your help ..

I'll award some points .. maybe something else comes up
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.