Hello everyone.
I have a usercontrol, and on the usercontrol I have a Panel.
What I want to do is to make the Panel the host for child controls, In other words, I want to add ( in design View ) controls to the panel on the usercontrol.
I did this in my layout event:
Private Sub HTG_Group_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles Me.Layout
Try
If e.AffectedControl.Name <> Me.Name And e.AffectedControl.Name <> pnlGBBody.Name And e.AffectedControl.Name <> lblGBHead.Name Then
Select Case e.AffectedControl.Top
Case pnlGBBody.Top To pnlGBBody.Top + pnlGBBody.Height
Select Case e.AffectedControl.Left
Case pnlGBBody.Left To pnlGBBody.Left + pnlGBBody.Width
If e.AffectedProperty.ToString() = "Bounds" Then
'set the parent
e.AffectedControl.Parent = pnlGBBody
pnlGBBody.Controls.Add(e.AffectedControl)
'calculate the top & left to drop it where the user intended
e.AffectedControl.Top = e.AffectedControl.Top - pnlGBBody.Top
e.AffectedControl.Left = e.AffectedControl.Left - pnlGBBody.Left
e.AffectedControl.PerformLayout()
End If
End Select
End Select
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Yes, it does add the controls to the panel, but, the moment I move any of the child controls, I get an error that the control I've added is disabled because there is no reference set to an instance of an object.
How do I catch it, how can I get over it ¿
Any help will be greatly appreciated.
It's Not Answers That Change The World, It's Questions