well i was PointToScreen() but when the control is inside a group box this method dont work and gives me wrong coordinates.
so is there is anyother method to get the position of a control inside a group box control?
i need that screen position so i can display a dialog near that control.
thanks
Asked
Active
Viewed 1.2k times
2

Karim
- 6,113
- 18
- 58
- 83
2 Answers
5
Probably you are using PointToScreen on the wrong control...
If you have a groupbox with a button then the following code works just fine:
Point p = groupBox1.PointToScreen(button1.Location);

Victor Hurdugaci
- 28,177
- 5
- 87
- 103
-
yeah this one works :) and if i have a nested group box then what will be the method? – Karim Aug 22 '10 at 07:10
-
Karim, I think is the same. Just use the parent's `PointToScreen` method for the control you want. – Victor Hurdugaci Aug 22 '10 at 07:53
2
I am not sure about this, but I think you can add the locations of the component and its containers.
For example, if you have a textbox inside a groupbox, you can do this:
Point p = textbox.location + groupbox.location + this.location;
"this.location" is used to get the location of the main form on the screen
Hope this will help...

Mahmoud Younes
- 63
- 7
-
i know this method but i didnt want to use it. this is why i asked on stackoverflow this question cause they should be a better way – Karim Aug 22 '10 at 07:07