I'm simply making a control using a class library and inheriting from Form.
I have this code that is found in the constructor for the 'form' control.
I wonder two things:
1) Is there a more elegant way to center the form? The code works but I have this feeling that what I did was convoluted.
2) The only way I could seem to get the owner of the control was to pass it in via the 'owner' parameter. Is there a way to obtain the owner without passing it in?
If I replace owner with Me.Parent or MyBase.Parent; it isn't set (NullReferenceException) even though the calling code within another form adds this control to it's control collection.
Code:Public Sub New(ByVal timeToBeVisible As Integer, ByVal owner As Control) MyBase.New() mTimeToBeVisible = timeToBeVisible Me.TopLevel = False Dim ParentScreenLocation As Point = PointToScreen(owner.Bounds.Location) ParentScreenLocation.Offset((owner.Width - Me.Width) \ 2, (owner.Height - Me.Height) \ 2) Dim MyLocation As Point = PointToClient(ParentScreenLocation) MyLocation.Offset(-owner.Bounds.Location.X, -owner.Bounds.Location.Y) Me.Location = MyLocation End Sub


Reply With Quote