|
-
Jul 26th, 2006, 01:12 PM
#1
Thread Starter
Hyperactive Member
[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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' some code
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' some code
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
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.
-
Jul 26th, 2006, 01:36 PM
#2
Frenzied Member
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.
-
Jul 26th, 2006, 01:45 PM
#3
Thread Starter
Hyperactive Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|