Click here to Skip to main content
15,913,262 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
can any one explain me what is it?


Thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 12-Jan-15 0:06am    
What do you mean by that? How about a code sample of what you tried to do?
—SA

So you mean: During design-time you copy a control from one desing-Form to another but the code for the Events (you mean the eventhandlers) used by the control isn't copied?
If you mean something else please try to find a better description of your problem....
If you have above described problem: Think about what should happen: The code may relay on internal/private variables of the original Form and won't work on another Form. So the Forms-Designer never copies (eventhandler) code if you copy a control. So it's up to you to recreate the eventhandler on another form (or use some other technique to avoid code-duplication - MVVM?)
 
Share this answer
 
It does not seem to make any sense: you could not possibly copy "control" to "another control event": events and controls are not assignment-compatible types.

Probably, you mean copying a control from one form to another form. This could be possible, in certain sense, but makes little sense. You need to understand that control is one of the reference type. If you just copy a control variable or a member, you don't get two objects. You end up with two references to the same object. Even if you use System.Object.Clone, it will be pretty much useless in most cases, because such clone is not deep. Please see:
http://en.wikipedia.org/wiki/Object_copy#Shallow_copy[^].

Essentially, to have two different controls (it doesn't matter if they are in the same form or different forms), you create a second instance of the control and copy some of the properties. At the same time, it's interesting that it's easy to move a control from one form to another, or to different parent control on the same form:
C#
Control controlInFirstForm = //...
Control parentInOtherForm =  // could be that form itself,
                             // or some other container control
                             // of this form: Panel, TabPage, etc
// now, do it:
controlInFirstForm.Parent = parentInOtherForm;
// the control will immediately "jump" between forms
// it will be visible if its Location allows that
// otherwise you need to adjust Location and/or Dock

Sometimes, such trick can be even needed, but quite rarely. :-)

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900