Reputation: 367
I'm writing a VB.Net WinForms application that has multiple data girds on any given form. On one such form, the data grids are loaded into split containers which in turn are located on a tab control. The load method for each data grid is threaded so that an animated "Loading" form can be shown. I would like to position the new loading form (which is smaller than the grid) on top of, and preferably in the center of, the grid that is loading.
Whats the easiest way to find the grids location within the main form so that I can adjust the loading forms location?
Upvotes: 0
Views: 3608
Reputation: 367
Solved. Comments? Other solutions?
Iterate through the parent controls until you find the main form. Add the point of each location to the previous.
Private Function Get_Control_Location(ByVal control As Control) As Point
If control.Name = "MainForm" Then
Return control.Location
End If
Return control.Location + Get_Control_Location(control.Parent)
End Function
Then calculate in the size of the new loading so that its centered on the grid.
Dim x As Integer = (GridControl.Width / 2) - (PleaseWait.Width / 2)
Dim y As Integer = (GridControl.Height / 2) - (PleaseWait.Height / 2)
PleaseWait.Location = Get_Control_Location(GridControl) + New Point(x, y)
I hope this helps someone else!
Upvotes: 2