views:

1025

answers:

4

i would like to create a simple winforms or wpf application where i can drag and drop virtual "cards". this below is not exactly what i want to do, but it the closest thing that i found on the web to represent the user interface.

http://www.greenpeppersoftware.com/confluence/plugins/advanced/gallery-slideshow.action?imageNumber=1&pageId=24870977&decorator=popup&galleryTitle=Task+board+and+transitions

so basically i want to have columns in the GUI where i can drag and drag from one to the other.

My questions are:

  1. would this be easier in winforms or wpf
  2. where do i start?
A: 

It would probably be slightly easier in WPF because of the Thumb control which provides easy to use built-in support for dragging. (If I remember correctly, in WinForms you would need to handle the mouse events yourself, whereas the WPF Thumb does this for you and translates them into drag start, delta and end events.)

However if you are much more familiar with one framework than the other than that would probably dwarf the difference that the Thumb control would make.

You should also have a look around for toolkits/frameworks that could handle this for you -- I think they exist for both WinForms and WPF (not sure though).

itowlson
+1  A: 

In both winForms and WPF dragging and dropping can be done in a similar way by working with the events on the target DragOver and Drop.

However with WPF you have other options. You will also be able to make the application look better by having a thumbnail as you drag (this is possible in winforms but harder to achieve).

Have a look at this WPF sample it uses a helper class and think it does exactly what you need.

John
+1  A: 

I agree with John in that WinForms and WPF are quite close to one another w.r.t. drag'n'drop. But WPF offers more of a "common base" for ItemsControl, allowing to implement more independent of the final UI elements used (ListBox, ListView, TreeView... can be easily switched). And obviously WPF allows much more fancy effects.

I would strongly recommend this blog post: http://www.beacosta.com/blog/?p=53 both for some drag'n'drop basics and for a clean WPF drag'n'drop approach. It shows a nice implementation of a rather generic helper for drag'n'drop from/to WPF ItemsControls, I really like that "Insertion Adorner". And I do like that the drag'n'drop code is nicely separated from the user control itself by using attached properties, which makes it much easier to use and maintain.

Simpzon
A: 

A good way for darg and drop are explained as

Detect a drag as a combinatination of MouseMove and MouseLeftButtonDown

Find the data you want to drag and create a DataObject that contains the format, the data and the allowed effects.

Initiate the dragging by calling DoDragDrop()

Set the AllowDrop property to True on the elements you want to allow dropping.

Register a handler to the DragEnter event to detect a dragging over the drop location. Check the format and the data by calling GetDataPresent() on the event args. If the data can be dropped, set the Effect property on the event args to display the appropriate mouse cursor.

When the user releases the mouse button the DragDrop event is called. Get the data by calling the GetData() method on the Data object provided in the event args.

You can find the complete article here

Sauron