Drag and Drop from one control to another

Discussions about document viewing.
Post Reply
zzfive03
Posts: 2
Joined: Fri Jun 29, 2012 3:24 am

Drag and Drop from one control to another

Post by zzfive03 » Fri Jun 29, 2012 3:41 am

Hello, i am brand new to gdpicture, and am evaluating the product. I need to create a win control that is a "document splitter". I want to have a main document, (shown in thumbnail view) and then several other thumbnail viewers that i can drag document pages into.

How might the code look on the drop event that will allow me to:
1) Add the selected thumbnails to the target control
2) Remove the selected documents from the source control
3) When i click my "split" button, how can i reference my now split thumbnails back to my origial document so I can do the actual splitting.


Thank you in advance for any guideance.

Mark.

zzfive03
Posts: 2
Joined: Fri Jun 29, 2012 3:24 am

Re: Drag and Drop from one control to another

Post by zzfive03 » Fri Jun 29, 2012 5:44 pm

Here is how I think i will solve it... (note, i am using PDF4NET to split, just because that was the tool I already had)

private void thumbnailEx2_DragDrop(object sender, DragEventArgs e)
{
string[] formats = e.Data.GetFormats();
ListView.SelectedListViewItemCollection coll = (ListView.SelectedListViewItemCollection)e.Data.GetData(formats[0].ToString());
MovePages(sOriginalFile, coll, sWorkingFolder + thumbnailEx2.Tag.ToString() + ".pdf");

}

private void MovePages(string sourcePath, ListView.SelectedListViewItemCollection sourcePages, string targetPath)
{
bool bDoesTargetExist = File.Exists(targetPath);

PDFDocument objOriginal = new PDFDocument(sourcePath);

PDFDocument objTarget;// = new PDFDocument();

if (bDoesTargetExist)
{
PDFDocument objT = new PDFDocument(targetPath);
objTarget = objT;
}
else
{
PDFDocument objT = new PDFDocument();
objTarget = objT;
}

foreach(ListViewItem item in sourcePages)
objTarget.Pages.Add(objOriginal.Pages[Convert.ToInt32(item.Text.Replace("Page ",""))-1]);


int iPagesRemoved = 0;
foreach (ListViewItem item in sourcePages)
{
objOriginal.Pages.RemoveAt(Convert.ToInt32(item.Text.Replace("Page ", "")) - 1- iPagesRemoved);
iPagesRemoved++;
}

objOriginal.Save(sourcePath);
gdViewer1.SetLicenseNumber("xxx");
gdViewer1.DisplayFromFile(sOriginalFile);
thumbnailEx1.LoadFromGdViewer(gdViewer1);

objTarget.Save(targetPath);
GdPicture.GdViewer viewer1 = new GdViewer();

viewer1.SetLicenseNumber("xxx");
viewer1.DisplayFromFile(targetPath);
thumbnailEx2.LoadFromGdViewer(viewer1);

}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest