I am fairly new to VB.Net. I have created a Custom Control with a couple of buttons on it. I am adding this control to a form programmatically at run time. I want one button on the control to be used to remove the control when it is clicked. I'm sure that there is a simple solution, but I am stumped.
My routine to add the control to the form works fine
I also have a button already on the form that will take the control down. That works fine.Code:Private DynamicControl As New Object() Private Sub cmdCreateNew_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdCreateNew.Click Dim NewControl As New ctrlCustomerInfo() NewControl.Left = 150 NewControl.Top = 100 Me.Controls.Add(NewControl) AddHandler NewControl.Click, AddressOf NewControl_Click DynamicControl = NewControl End Sub
What I want to do is use a button that is on the new control in order to take the control down, but I can’t figure out how to do that.Code:Private Sub cmdClear_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdClear.Click Dim MyControl As ctrlCustomerInfo MyControl = DynamicControl Me.Controls.Remove(MyControl) End Sub
Any help would be greatly appreciated




Reply With Quote