How to place a control relative to another control


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I'm having a heck of a time figuring this out.



I have a control that is within a tab, that is in toostripcontainer. I want to programmatically place a control (a label) such that the upper left corner of the label is right below the controls lower left corner. Now this is trivial if they are both in the same container, in this case the tab page. Alas, that is not the case. The label is in the form's control collection, not the tabs.



My first try was to get the point that is at the lower left of the control in the tab, translate it to screen coordinates, then translate it back to client coordinates, but relative to the form:



Dim lowerLeftClient As Location = New Location(theControl.Left, theControl.Top + theControl.Height)

Dim lowerLeftScreen As Location = theControl.PointToScreen(lowerLeftClient)

Dim lowerLeftForm As Location = theControl.ParentForm.PointToClient(lowerLeftScreen)

theLabel.Location = lowerLeftForm




This typically results in the label being too low and too far right.



Then I thought maybe the PointToClient relative to the form was including the borders and header, but when setting the location, these were not. So I attempted to take this into consideration by comparing the Size of the form to the ClientSize. I figured the X difference \ 2 should be the left border width (or close) and maybe the Y difference minus the border width would be the header height. Alas, this degraded into finding magic numbers...which changed on every form/layout. Crazy



So, if you've followed this far, I'm hoping you can help me figure out how to retrieve a location relative to the form itself, of a control buried within other control(s). Ermm



Thanks!







GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search