I have an MDI application that allows me to open different types of child windows. I can open multiple (but different) instances of the same type of child window. (Example: I can open 3 instances of child window type A and 2 instances of child window type B. All 5 windows are distinct entities and do not share data until unless the user explicitly drags the same data onto multiple windows.) Each child window has a ToolStripContainer with one or more ToolStrips. How do I prevent:
- the user from dragging a ToolStrip from a child window of type A to a ToolStripContainer in a child window of type B?
- the user from dragging a ToolStrip from one instance of child window A to a ToolStripContainer in another instances of the same type of window?
I'm trying to prevent the user from dragging a ToolStrip from instance 1 of type A to instance 2 of type A, selecting some stuff on instance 2, and then clicking a button on the toolbar only to have something weird happen to some other window. Similarly it doesn't make sense to drag a ToolStrip from a window of type A to a window of type B -- the actions don't apply to that type, but to the user it looks like everything is fine because I let them do the drag.
Is it as simple as adding my own handler for the ControlAdded event or is there a better way to do this? I'm using WinForms in .NET 3.0.
edit: Steps to reproduce
- Create a new Windows Application project.
- Add a new user control. Give the control a ToolStripContainer that contains one ToolStrip with a single button.
- Repeat step 2, giving you a UserControl2 class.
- Compile the solution so UserControl1 and UserControl2 show up in your toolbox.
- Drag UserControl1 and UserControl2 onto the form. Set the borders so you know where the boundaries are.
- Run the app.
- It's now possible to drag the ToolStrip from the container in UserControl1 and drop it into the container in UserControl2 (leaving zero ToolStrips in UC1 and two ToolStrips in UC2.)
- Now imagine you only have access to the code in UserControl1. How do you prevent the user from dragging the ToolStrip out of that instance of the ToolStripContainer?