Custom MenuItem
-
I have been tasked with creating a custom MenuItem. I can easily derive a class from System.Windows.Forms.MenuItem and add some methods to it. However, where I am having a problem is adding drag/drop capability. I need to be able to drag a MenuItem onto a toolbar. MenuItems do not support the DoDragDrop method which is what I would normally use. Is it possible to add DragDropEffects to a MenuItem? Thanks, Bill
-
I have been tasked with creating a custom MenuItem. I can easily derive a class from System.Windows.Forms.MenuItem and add some methods to it. However, where I am having a problem is adding drag/drop capability. I need to be able to drag a MenuItem onto a toolbar. MenuItems do not support the DoDragDrop method which is what I would normally use. Is it possible to add DragDropEffects to a MenuItem? Thanks, Bill
You can fake it pretty easily. When the MenuItem catches a mouseDown, change the cursor of the MenuItem and the main application to something that looks like a cursor with a drag item. Then set your desired receiver's state to 'RECEIVING'. When the receiving control catches a mouseUp and it's in the 'RECEIVING' state, it will perform the operation just as if the MenuItem was really dragged. Now just set the cursor for the MenuItem and main application back to default.
-
You can fake it pretty easily. When the MenuItem catches a mouseDown, change the cursor of the MenuItem and the main application to something that looks like a cursor with a drag item. Then set your desired receiver's state to 'RECEIVING'. When the receiving control catches a mouseUp and it's in the 'RECEIVING' state, it will perform the operation just as if the MenuItem was really dragged. Now just set the cursor for the MenuItem and main application back to default.
if_mel_yes_else_no wrote: You can fake it pretty easily. When the MenuItem catches a mouseDown The problem is that a MenuItem doesn't have standard MouseDown/Up/Move events. It just has a Click event whose parameter is a plain System.EventArgs not MouseEventArgs so I don't have access to the information that would be in MouseEventArgs. Without being able to detect if I have a left or right-click or if the Ctrl key is pressed I don't see how to tell the difference between a normal click on a MenuItem and the click that is to start the drag operation. Thanks, Bill
-
if_mel_yes_else_no wrote: You can fake it pretty easily. When the MenuItem catches a mouseDown The problem is that a MenuItem doesn't have standard MouseDown/Up/Move events. It just has a Click event whose parameter is a plain System.EventArgs not MouseEventArgs so I don't have access to the information that would be in MouseEventArgs. Without being able to detect if I have a left or right-click or if the Ctrl key is pressed I don't see how to tell the difference between a normal click on a MenuItem and the click that is to start the drag operation. Thanks, Bill
You must be using studio 2003. In studio 2005 the MenuItems have all the mouse events. There's a chance that you could look into having the application catch any system mouseDowns, and using the mouseEventArgs's X and Y coordinates, try to figure out if it came from your menuItem... but that sounds like a lot of hassle. How about a seperate menu item called "Add Bla". After you click it the cursor changes as I said before, and you can click on the receiver. It's not exactly a drag so much as a 'click to place', but it's better than nothing.
-
You must be using studio 2003. In studio 2005 the MenuItems have all the mouse events. There's a chance that you could look into having the application catch any system mouseDowns, and using the mouseEventArgs's X and Y coordinates, try to figure out if it came from your menuItem... but that sounds like a lot of hassle. How about a seperate menu item called "Add Bla". After you click it the cursor changes as I said before, and you can click on the receiver. It's not exactly a drag so much as a 'click to place', but it's better than nothing.