I have a question about drag and drop in WinForms. I know how to enable the user to drag and drop controls around inside the form, but what I'm now trying to do is enable them to drag a LinkLabel ontop of a"Recycle Bin" icon inside my Form and when it detects that something has been dropped onto the Recycle Bin icon, that control will be removed from the Form.
How would I detect if something's been dropped on another control? Would I still use Control.DragEnter & Control.DragDrop?
Thank you
yes, DragEnter and DragDrop is the right way to go, also you need to handle DragOver.
Typically, in these handler you specify what kind of drag-drop is allowed, and in DragDrop do your staff of deleting.
Here is the helpful link for you which can explain you about the DragDrop.
http://www.codeproject.com/KB/combobox/LarryDragAndDrop.aspx
You require to work on following Events:
1. MouseDown 2.DragEnter 3. DragDrop
Related
Is there a way to send message (like mousedown) to a control?
My purpose is that when you click GridView, prevent mousedown behavior itself and bypass mousedown message to RepositoryItem.
From your question: "My purpose is that when you click GridView, prevent mousedown behavior itself and bypass mousedown message to RepositoryItem."
It sounds like you want to control the behavior of the Mouse Down event on the control. Right?
If that's the case, on the Winforms designer, look at the properties panel. On there is also a selection for the form events for a control. You can scroll down and find the Mouse Down event and add an event handler. Then do whatever filtering you need including not even processing the message at all.
You also mentioned that it's a DevExpress control. I recall that some of their controls were wired up a little differently so the DevExpress website might have some additional clues.
When I need to re arrange positions of buttons of controls I use copy/cut and paste but I lose the asociation of the events and need to re assign manually.
Is there a way to do that without losing them?
For example I cut a button and paste it elsewhere.
It had associated the bt_ClickEventFunction, but when pasting it, it loses this.
You can drag them on the Form in order to change their location, you don't need to cur&paste them.
Copy&Paste creates another control with new name and Text while Cut&Paste deletes everything from designer and then regenerates the control as it were but without lines for adding events. I presume that this is because the code for events handlers is in file other that the file created by designer and when you cut the control, event handler doesn't gets deleted from the code since it can be the event handler for some other control also. So when pasting, designer actually only creates the new control as it would when you drag it from the Toolbox but sets the properties from the control hat has been cut.
EDIT Edit based on your comments.
You can do drag&drop even with TabPages. You need to drag it for the small rectangle with arrows like shown on the image:
and you can drag it to the other TabControl, in that case, TabPage will retain all "associated" event handlers.
To restore all the event procedures to their respective controls, go to the VBA code window of the form and then cut, copy and paste the whole module. You may press Ctrl+A, Ctrl+X and Ctrl+V to do so.
My form has several textboxes and several buttons. The textboxes are loaded with data by the load event. If I make changes to the textboxes and then move the cursor over a button, the textboxes are suddenly loaded again with the original information. I don't click a button. I just move the mouse over one. Why is this happening and how do I stop it?
This cannot happen by itself. I suggest you check all event-settings.
For instance, you could have, by accident, linked the Load event to the Button's OnMouseEnter or something like that.
After your comment:
You should absolutely not use the paint event to initialize things. The paint event will be called after every change in the Form.
So move that code to the Load event.
In my C# app, I have a ListView on a Form. I want the user to be able to double-click on a section of the ListView when no items are selected in order to pop up a "New Item" dialog. The problem is that the DoubleClick event for the ListView only fires if an item is selected.
Is there a way to do this?
There is a way to do this, but you have to do some low-level drilling into the Windows machinery. It's generally not a good idea to spend a great deal of time trying to get a standard Windows control to behave in a non-standard manner.
A simpler way is to just put a "New Item" button next to your ListView. If screen real estate is an issue, you could just add an extra row at the bottom that says "{click here to add new item}", and show your dialog when the user clicks this last row.
Add an event handler for the List view's MouseDoubleClick event.
Assuming Windows Forms:
Perhaps a good workaround would be to use a ContextMenu.
I'm trying to implement drag and drop capability into a custom data grid control. In the end, I'd like to be able to drag rows between 2 of these custom data grids. I believe I have everything working as expected. However, I need to do some cleanup in the drag and drop source control. Specifically, I need to refresh the grids after items are moved. How do I do this? If it make any difference, these grids are not bound to a data source (for other reasons I won't explain).
You supposed to perform post-drop operation on the drag source in the MouseMove event handler after the call to DoDragDrop() returned and on the drop target in the DragDrop event handler.