Solved

Get absolute position of a control on a form

Posted on 2004-09-09
8
1,459 Views
Last Modified: 2008-01-09
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
Comment
Question by:somnatic
  • 3
  • 2
8 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 500 total points
ID: 12015906
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
 
LVL 4

Author Comment

by:somnatic
ID: 12015971
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
 
LVL 20

Expert Comment

by:TheAvenger
ID: 12016039
Hmm, that's interesting. Have you tried the Bounds property? Or the Location property?
0
 
LVL 4

Author Comment

by:somnatic
ID: 12016252
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
 
LVL 4

Author Comment

by:somnatic
ID: 12110274
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question