tags:

views:

22

answers:

2

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

A: 

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
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
+2  A: 

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
yeah this one works :)and if i have a nested group box then what will be the method?
Karim
Karim, I think is the same. Just use the parent's `PointToScreen` method for the control you want.
Victor Hurdugaci