Results 1 to 3 of 3

Thread: [2005] Cut/paste controls on form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497

    [2005] Cut/paste controls on form

    I noticed behavior has changed when cutting/pasting controls on forms that does not preserve/attach the code under the control to the pasted control.

    For example, in a button's click event, I am referring to how the Handles Button1.Click part of the Sub declaration is removed from the original code and attached to a new sub-block. I understand the reason, but my question is:

    When you want to cut and paste controls on the same form, how can you avoid this or what is the best practice for doing it? For example, I often do this when I decide I want to put my controls on a groupbox after I have alreaady coded events for them. I usually "cut" all the controls, lay down the groupbox and then "paste". But then I have to modify all this other code.


    Here's an example of what I mean, in case it's not clear:
    1) Drop a command button on a form.
    2) Double click on it and add code to its click event that looks like:
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         ' some code
    3.     End Sub
    3) Select command button on form and "cut".
    4) Paste the button from the clipboard back onto the form.
    5) Double-click on button and you get a new sub block with the old sub block modified:
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    2.         ' some code
    3. End Sub
    4. Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.  
    6. End Sub

    What I've been doing is copying the Button1_Click complete sub code, deleting all the Button1_Click subs, then clicking on the button again to create a new event-with Button1_Click as its name and pasting the code back in. Is there a better way?

    Thanks for anything.
    end war
    stop greed

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] Cut/paste controls on form

    I believe this is in the .Net tips at the top of the forum. Yes when you cut and paste controls they lose their handle. The only way around this is not cut and paste. Instead move the controls.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497

    Re: [2005] Cut/paste controls on form

    I checked that out, and that's new too: that you can drag a control into a container. Gee, I'm so out-of-touch with what's new.

    I guess I can also put back the Handles... code at the end of the original subs. It's just such an implicit thing that happens, I was wondering if there was a way to turn it off.

    Thanks for your reply.
    end war
    stop greed

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