Hi there!
Is there any way I can clone/make a copy of a control without copying properties 1 by 1?
What I'd really like to do, is to have a function receiving a control as input, and then make a new copy of that control.
best reg
BIW
Printable View
Hi there!
Is there any way I can clone/make a copy of a control without copying properties 1 by 1?
What I'd really like to do, is to have a function receiving a control as input, and then make a new copy of that control.
best reg
BIW
Dim blah As ControlName = OldControl
???
Naww...
That just references the other control, doesn't make a copy
For instance:
VB Code:
Dim txtA As New TextBox() txtA.Text = "first value" Dim txtB As TextBox = txtA txtB.Text = "second value" MsgBox(txtA.Text)
... returns "second value", not "first value" as desired.
i think is memberclonewise or something like that
Create an own TextBox and inherit from System.Windows.Forms.TextBox and implement the ICloneable interface
/Leyan
You can do something like this:
VB Code:
Dim txt As New TextBox() 'Me.Controls.Add(txt) Dim pi As Reflection.PropertyInfo For Each pi In TextBox2.GetType.GetProperties If pi.CanWrite Then On Error Resume Next 'just in case Me.GetType.GetProperty(pi.Name).SetValue(Me, pi.GetValue(TextBox2, Nothing), Nothing) End If Next 'txt.Location = New Point(10, 10)
But some it doesn't work so great and I'm not sure why.