Results 1 to 9 of 9

Thread: copy control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    Netherlands
    Posts
    115

    copy control

    I've got a control, named Winsock. I want to copy this control and rename it. is this possible? if yes, how?

    VIP

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Edit Copy
    Edit Paste

    would do I should think...

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    u want to copy it using VB, use FileCopy ?
    -= a peet post =-

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    Netherlands
    Posts
    115
    something like that. I want to do this when the program is running. (when you click a button)

    VIP

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    If you are doing the copy on the same form, it will ask if you want to create a control array. Say no, and the new control's name should default to WinSock1. It would be best to save the form first. That way you can always reload if something goes awhacky.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    You must have posted at the same time I did. Anyway, I didn't realize you want to do this at runtime. Should be a problem though. First, in design mode, you will need to create a control array of your Winsock control. So, add a second control, give it the same name, and say "Yes" when asked if you want to create the array.

    Now your control will be named something like Winsock(0).

    The 0 represents the index of the array. Then, at runtime you can use Load to create a new control by saying
    VB Code:
    1. Private Sub cmbField_Click(Index As Integer)
    2.    
    3.     If cmbField(0).Text = "** Find All Records **" And cmbOperator(0).Visible = True Then
    4.         Picture1.SetFocus
    5.         Exit Sub
    6.     ElseIf cmbField(0).Text = "** Find All Records **" Then
    7.         Exit Sub
    8.     End If
    9.  
    10.     If cmbField(Index) > "" Then
    11.  
    12.         'Load a new instance of the criteria and condition lists if needed...
    13.         On Error Resume Next
    14.         If Index >= 0 Then
    15.             Load txtCriteria(Index)
    16.             txtCriteria(Index).Top = txtCriteria(0).Top + (Index * 330)
    17.             txtCriteria(Index).Text = ""
    18.             Load cmbOperator(Index)
    19.             cmbOperator(Index).Top = cmbOperator(0).Top + (Index * 330)
    20.             cmbOperator(Index).Tag = ""
    21.             If Index < 4 Then
    22.                 Load Condition(Index)
    23.                 Condition(Index).Top = Condition(0).Top + (Index * 330)
    24.                 If Condition(Index).ListCount = 0 Then
    25.                     Condition(Index).AddItem "And"
    26.                     Condition(Index).AddItem "Or"
    27.                 End If
    28.             End If
    29.         End If
    30.         txtCriteria(Index).Visible = True
    31.         cmbOperator(Index).Visible = True
    32.         cmbOperator(Index).TabIndex = cmbField(Index).TabIndex + 1
    33.         txtCriteria(Index).TabIndex = cmbField(Index).TabIndex + 2
    34.         Condition(Index).TabIndex = cmbField(Index).TabIndex + 3
    35.         If Index < 4 Then
    36.             Condition(Index).Visible = True
    37.         End If
    This is code that I use in one of my programs to programmatically create a series of combo boxes depending on what the users wishes (not show). You should be able to modify this to do the same with your Winsock control.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    Netherlands
    Posts
    115
    thanks for your reply but the most inpotant thing of the hole action is the renaming. I want to rename the control after I copied it.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I don't believe you can programmatically rename a control at runtime. All you can do is Load a new instance of it.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    Netherlands
    Posts
    115
    okey, thanks!

    VIP

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