Solved

Get absolute position of a control on a form

Posted on 2004-09-09
8
1,456 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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