|
-
Jul 1st, 2004, 10:56 AM
#1
Thread Starter
Member
Getting the Location of a control on a form
I have a textbox created in code and displayed on a form.
I need to get the location of the control within the form.
I'm able to get it using
textBox.Location if the control is placed on a form.
BUT, if the control is placed inside a GroupBox (frame) then
textBox.Location return the location of the textBox inside the frame and not the location of the texBox compared with the form.
any ideas how I can get the Location based on the form
note: the my control can any be placed on the form, inside another control or inside a another control that is also inside another control, i.e. a frame in a frame.
-
Jul 2nd, 2004, 04:51 AM
#2
Thread Starter
Member
to simplify, all I really need is the Location (x,y coords) of my control relative to the form, and not relative to a frame that it is in.
-
Jul 2nd, 2004, 06:14 AM
#3
Didn't feel like starting a new C# project, so here it is in VB...
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim pt As Drawing.Point = Button1.Location
pt = Button1.PointToScreen(pt)
pt = Button1.TopLevelControl.PointToClient(pt)
MsgBox("Top:" & pt.Y & "; Left:" & pt.X)
End Sub
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|