CUTand PASTE controls: where is the code?

T

teo

When I Cut and Paste controls

(ie: from a 'Form' to a 'Tab control'
that I just put on the Form)

the pasted controls regularly arrive with their properties,
but the code behind them
remains ouside the form,
like user written subs remain

infact,
if I double-click on a pasted control
the displayed routine is empty
and now it is called
button_click_1
and not
button_click

is there a way to have the code of a pasted control
regularly "bound" to the pasted control?
 
L

lord.zoltar

teo said:
When I Cut and Paste controls

(ie: from a 'Form' to a 'Tab control'
that I just put on the Form)

the pasted controls regularly arrive with their properties,
but the code behind them
remains ouside the form,
like user written subs remain

infact,
if I double-click on a pasted control
the displayed routine is empty
and now it is called
button_click_1
and not
button_click

is there a way to have the code of a pasted control
regularly "bound" to the pasted control?

I don't think this is possible.
 
J

jeff

from what I have seen ... this is what happens me ...when you cut and paste
a control on a form ...

assume Button1 is the control you want to move...

before cut ... u have
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

when control is cut...
- ide goes to the code and removes all the event handles associated to the
control....
- so the following is what appears

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

- the handles part of the sub is GONE!
- i assume it does this for you so there is no compilation errors...

when the control is pasted...
- the IDE does not automatically set the handles to the 'pasted' control


So, as I said, this is was appears to happen to me whenever I move a control
from one object to another ... ie form to tab page. To avoid this, what I
do is ... copy the control to the tab-page ... go to the code page ... find
and replace old name with new name ... Button1 with Button2 ... delete the
origional control and rename the new control to the origional control...
sounds flaky but it worked when I need it to. This is an arguement / reason
for manually wiring up your events to your controls ...

Again, this is what I experienced, this may or may be the same as your
problem.
 
L

lord.zoltar

Yeah I've seen that too...

When you copy and paste a control WITHOUT deleting the original, then
the event handler for the original also becomes the handler for the
pasted control. I find this especially annoying with buttons.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top