Copying UserControl Variables
-
Hi! I have a few instances (say 10) of a UserControl, each with 5 properties, on a Form. I want to implement a "Copy From" function that works the following way: 1. The user can right click on any UserControl. The right click menu allows the user to select a Copy From menu item which springs up a ToolStripComboBox with a list of other similar controls. 2. Once the user selects an instance of the UserControl in the ToolStripComboBox, that UserControl's properties are to be copied to the current UserControl. Each UserControl has a ControlID property that is unique to it (listed in an eControlID enum.) This property will not be copied over. However, the ToolStripComboBox is populated with all the IDs (say A...Z) to help the user identify the UserControl whose properties he wants copied. I have got this far:
private void ContextMenuCopyFrom_SelectedIndexChanged(object sender, EventArgs e) { this.ControlID= (eControlID)ContextMenuCopyFrom.SelectedIndex; }
How do I actually figure out which UserControl has been selected to copy from and then copy the properties. I figure it'll be something likethis.Property1 = UserControlSelected.Property1; this.Property2 = UserControlSelected.Property2; // etc
-
Hi! I have a few instances (say 10) of a UserControl, each with 5 properties, on a Form. I want to implement a "Copy From" function that works the following way: 1. The user can right click on any UserControl. The right click menu allows the user to select a Copy From menu item which springs up a ToolStripComboBox with a list of other similar controls. 2. Once the user selects an instance of the UserControl in the ToolStripComboBox, that UserControl's properties are to be copied to the current UserControl. Each UserControl has a ControlID property that is unique to it (listed in an eControlID enum.) This property will not be copied over. However, the ToolStripComboBox is populated with all the IDs (say A...Z) to help the user identify the UserControl whose properties he wants copied. I have got this far:
private void ContextMenuCopyFrom_SelectedIndexChanged(object sender, EventArgs e) { this.ControlID= (eControlID)ContextMenuCopyFrom.SelectedIndex; }
How do I actually figure out which UserControl has been selected to copy from and then copy the properties. I figure it'll be something likethis.Property1 = UserControlSelected.Property1; this.Property2 = UserControlSelected.Property2; // etc
You can go through the Controls collection of the form and check the type of control. If the control is of the same type of your user control, match the ControlId with the controlId selected in the combo. If matches, thats the control user wanted.
Every bit counts
ADD
-
You can go through the Controls collection of the form and check the type of control. If the control is of the same type of your user control, match the ControlId with the controlId selected in the combo. If matches, thats the control user wanted.
Every bit counts
ADD
Is there any way of doing this without using a collection of controls? Can I match the SelectedIndex to a member of the enum and then copy the properties of that particular object?