Reputation: 509
I'm using a video capturing control called VideoCapX and I've hit a bug, and after hours of debugging, I've determined that the only way to fix the glitch is to restart the program aka. reset the control.
I'm wondering is there any way to programmatically recreate a GUI control aka reset it to the way it was when the form opened.
I know this is a cheap fix, but at this point it's my only option.
Upvotes: 0
Views: 53
Reputation: 54457
In general, this would work:
Me.SomeControl1.Dispose()
Me.SomeControl1 = New SomeControl
'Configure SomeControl1 here.
Me.Controls.Add(Me.SomeControl1)
where SomeControl1
is the field created automatically when you add the control to the form at design-time. The first line removes the existing control from the form, the second line replaces the existing control with a new one of the same type and the last line adds the new control to the form. You need to set the appropriate properties of the new control in between, so you might want to keep the old one around to get the required property values from, e.g.
Dim newControl As New SomeControl
'Configure newControl here, e.g.
newControl.Location = Me.SomeControl.Location
Me.SomeControl1.Dispose()
Me.SomeControl1 = newControl
Me.Controls.Add(Me.SomeControl1)
Note that assigning the new control to the existing field will automatically connect any event handlers with a Handles clause.
That said, the fact that you're using what is likely to be a fairly complex custom control, it's hard to say whether there might be some other required steps too.
Upvotes: 2