Hi I have been writing VB.Net for a few weeks,
it has been going well but I am now stuck.
I have multiple user controls on a form and I need a way to remove a selected one. I was hoping that something like this would do it
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Controls.RemoveByKey("UserControl")
refresh_Form()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Controls.RemoveByKey("UserControl1")
refresh_Form()
End Sub
But this only works for Button1, I am guessing this is because each instance is not called. “UserControl” and “UserControl1”. I have added the user controls using code and was wondering if there is anything I could do at the point of adding them, to idenfy them for later on. (i.e give them a name I could use later on)
Sorry if this is a daft question, it’s all fairly new to me.
Many thanks in advance