Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Alex Kon  
#1 Posted : Wednesday, November 28, 2007 2:43:55 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hi everyone!

Here is simple and easy to undestand project, which illustrates how you can implement drag-n-drop operations with two our most popular controls: Bitmap Viewer and Thumbnail List. The most essential code of the sample is posted below and the whole project you can find in post attachments.

Screenshot:

UserPostedImage

How it was done - first of all we should add Drag-n-Drop event handlers to the controls
Code:
public Form1()
{
	InitializeComponent();

	_bv = new Aurigma.GraphicsMill.WinControls.BitmapViewer();
	... skipped ...
	_bv.AllowDrop = true;
	_bv.DragEnter += new DragEventHandler(BitmapViewerDragEnter);
	_bv.DragDrop += new DragEventHandler(BitmapViewerDragDrop);

	_tl = new Aurigma.GraphicsMill.WinControls.ThumbnailListView();
           ... skipped ...
	_tl.ItemDrag += new Aurigma.GraphicsMill.WinControls.ItemDragEventHandler(ThumbnailListItemDrag);
}

Now we can respond to user actions:
Code:
void ThumbnailListItemDrag(object sender, Aurigma.GraphicsMill.WinControls.ItemDragEventArgs e)
{
	if (e.MouseButton == MouseButtons.Left)
	{
		Aurigma.GraphicsMill.WinControls.ThumbnailListItem item = 
			(Aurigma.GraphicsMill.WinControls.ThumbnailListItem)e.Item;
		DoDragDrop(new DragDropData(item.Pidl), DragDropEffects.Move);
	}
}


void BitmapViewerDragEnter(object sender, DragEventArgs e)
{
	if (e.Data.GetData(typeof(DragDropData)) != null)
		e.Effect = DragDropEffects.Move;
	else
		e.Effect = DragDropEffects.None;
}


void BitmapViewerDragDrop(object sender, DragEventArgs e)
{
	DragDropData myData = (DragDropData)e.Data.GetData(typeof(DragDropData));
	if (myData != null)
	{
		System.IO.Stream stream = myData.Pidl.Stream;
		_bv.Bitmap.Load(stream);
		stream.Close();
	}
}

DragDropData is trivial class which contains only reference to the PIDL of the dragged item. In your code you may pass PIDL object without any wrappers, but I prefer to use it because it guarantees that the action was initiated by my code and will provide an easy way for future extension.

Note that attached archive with sample source code doesn't include Graphics Mill for .NET assemblies, so you should update references to the Graphics Mill before compilation.

Edited by moderator Monday, May 28, 2012 8:46:10 PM(UTC)  | Reason: Not specified

File Attachment(s):
DragThumbnailToBitmapViewerSample.zip (11kb) downloaded 27 time(s).
DragThumbnailToBitmapViewerSampleVB.zip (13kb) downloaded 28 time(s).
Alex Kon attached the following image(s):
ScreenShot.jpg
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.