Results 1 to 6 of 6

Thread: How to clone a control?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    74

    Question How to clone a control?

    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
    Last edited by biw; Nov 22nd, 2002 at 07:15 AM.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Dim blah As ControlName = OldControl

    ???
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    74
    Naww...

    That just references the other control, doesn't make a copy

    For instance:

    VB Code:
    1. Dim txtA As New TextBox()
    2.         txtA.Text = "first value"
    3.  
    4.         Dim txtB As TextBox = txtA
    5.  
    6.         txtB.Text = "second value"
    7.         MsgBox(txtA.Text)

    ... returns "second value", not "first value" as desired.

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i think is memberclonewise or something like that
    \m/\m/

  5. #5
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    Create an own TextBox and inherit from System.Windows.Forms.TextBox and implement the ICloneable interface

    /Leyan

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can do something like this:
    VB Code:
    1. Dim txt As New TextBox()
    2.         'Me.Controls.Add(txt)
    3.         Dim pi As Reflection.PropertyInfo
    4.         For Each pi In TextBox2.GetType.GetProperties
    5.             If pi.CanWrite Then
    6.                 On Error Resume Next 'just in case
    7.                 Me.GetType.GetProperty(pi.Name).SetValue(Me, pi.GetValue(TextBox2, Nothing), Nothing)
    8.             End If
    9.         Next
    10.         'txt.Location = New Point(10, 10)

    But some it doesn't work so great and I'm not sure why.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width