블로그 이미지
생각처럼

카테고리

전체보기 (209)
TOOL (1)
다이어리 (1)
Bit (200)
HELP? (0)
Total
Today
Yesterday

달력

« » 2025.1
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

공지사항

태그목록

최근에 올라온 글

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:

  1. the user from dragging a ToolStrip from a child window of type A to a ToolStripContainer in a child window of type B?
  2. 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

  1. Create a new Windows Application project.
  2. Add a new user control. Give the control a ToolStripContainer that contains one ToolStrip with a single button.
  3. Repeat step 2, giving you a UserControl2 class.
  4. Compile the solution so UserControl1 and UserControl2 show up in your toolbox.
  5. Drag UserControl1 and UserControl2 onto the form. Set the borders so you know where the boundaries are.
  6. Run the app.
  7. 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.)
  8. 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?
link|edit|flag

40% accept rate
I tried to reproduce the problem that you are having but I can't seem to get it to work. Once I create two instances of the same form I can't drag the toolbar from one to the other in the first place – Nathan W Nov 18 '08 at 22:39

This feels like a hack, but it works (kind of) (sorry, vb.net not c#):

Public Class UserControl2

   
Private Sub tsMainMenu_BeginDrag(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsMainMenu.BeginDrag

        tsMainMenu
.Tag = tsMainMenu.Parent

   
End Sub

   
Private Sub ToolStrip1_EndDrag(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsMainMenu.EndDrag


       
If Not tsMainMenu.Parent.Parent.Equals(CType(tsMainMenu.Tag, ToolStripPanel).Parent) Then

           
CType(ToolStrip1.Tag, ToolStripPanel).Controls.Add(tsMainMenu)
       
End If

   
End Sub

End Class

simply put; when the control is finished being dragged, if its parent ToolStripContainer is not the same as it was when it started dragging, move the toolstrip back to where it was.

im sure this could be rolled into a control so that you dont have to write it for every toolbar.

Edit: You could put all this code into a control that inherits from ToolStripContainer, and have it do all the work for you, meaning a nice encapsulated solution.

Posted by 생각처럼
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함