Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1468
  • Last Modified:

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)
0
somnatic
Asked:
somnatic
  • 3
  • 2
1 Solution
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now