Solved

Get absolute position of a control on a form

Posted on 2004-09-09
8
1,452 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
Comment Utility
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
Comment Utility
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
Comment Utility
Hmm, that's interesting. Have you tried the Bounds property? Or the Location property?
0
 
LVL 4

Author Comment

by:somnatic
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Voice recognition ASP or ASP.NET or JavaScript 2 44
Default parameter problem in C# 3 26
c# code 19 57
bulid json format 3 16
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now