【发布时间】:2018-08-24 08:56:17
【问题描述】:
我正在尝试克隆我的 Windows 窗体自定义控件。
在里面,我有
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
使用它的 Windows 窗体有一个命令按钮来克隆。要克隆的对象名为cFlb。
我是这样使用的:
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
在两个项目中都能很好地编译。
cFlb.Visible = False 上的断点让我检查cFlb 属性。一切都应有尽有,尤其是深层复制元素。克隆的位置和原来的一样。
我唯一的问题是:我没有看到克隆。简直什么都没有。
我错过了什么?
【问题讨论】:
-
位置一样,但是大小呢?
-
无论如何,用一个简单的表单和 1 或 2 个控件创建一个 minimal reproducible example。
-
您是否克隆了 Parent 属性?
标签: .net vb.net custom-controls clone