Reputation:
I am trying to clone my Windows Form custom control.
In it, I have
Public Class UFB
Implements ICloneable
...
Public Function Clone() As Object Implements ICloneable.Clone
'Copy this instance's properties.
Dim oClone As New UFB With {
.BackColor = Me.BackColor,
'Another few dozen properties.
... }
'Deep copy of objects in a dictionary (loop).
...
Return oClone
End Function
...
End Class
The Windows Form using this has a command button to clone. The object to be cloned is named cFlb
.
I use it like this:
Public Class FMain
Dim WithEvents cFlbClone As UFB
Private Sub Clone()
cFlbClone = CType(cFlb.Clone, UFB)
cFlbClone.BackColor = Drawing.Color.Yellow 'Make it distinguishable.
cFlbClone.Visible = True
cFlb.Visible = False
End Sub
End Class
Compiles well in both projects.
A breakpoint on cFlb.Visible = False
let's me inspect the cFlb
properties. All is there as it should be, especially also the deep copy elements. The position of the clone is the same as the original's.
The only problem I have: I don't see the clone. There's simply nothing.
What do I miss?
Upvotes: 0
Views: 39
Reputation: 11801
For a control to be visible, it must be parented to either the Form or another control that that has the form as its TopLevelControl. If any ancestor control is not visible, the subject control will also not be visible.
The can be accomplished either by setting the control's Parent Property or adding the control to the parent control's Controls Property.
Upvotes: 1