I have a WinForm application using a FlowLayoutPanel that displays .TIFF files that have multiple pages. The FlowLayoutPanel displays all the pages in a ThumbNails View.
I have implemented the Drag Drop Logic which works fine for individual items. Now, I would now like to change it to allow the user to select multiple thumbnails (using the CTRL or the Shift Key) and drag drop to a different spot.
//** Logic after each thumbnail is generated:
PictureBox thumb = new myProject.utility.PictureBox(pageNum);
thumb.Image = doc.getThumb(pageNum); //since we pre loaded, we won't stall the gui thread.
thumb.Click += new System.EventHandler(
(thumbSend, thumbEvent) =>
{
highLightThumb(thumb.getPage());
}
);
thumb.DoubleClick += new System.EventHandler(
(thumbSend, thumbEvent) =>
{
selectedDoc = thumb.getPage();
me.Visible = false;
}
);
thumbFlow.Controls.Add(thumb);
if (selectedDoc == pageNum)
highLightThumb(pageNum);
//** Highlight Methods
private void highLightThumb(int page)
{
//clear highlight
foreach (Control c in thumbFlow.Controls)
{
if (c is PictureBox)
{
((PictureBox)c).highlight = false;
}
}
//apply highlight
foreach (Control c in thumbFlow.Controls)
{
if (c is PictureBox)
{
PictureBox thumbFrame = (PictureBox)c;
if (page == thumbFrame.getPage())
thumbFrame.highlight = true;
}
}
}
Below is the existing drag drop logic.
//**********************//
//** Drag/Drop Events **//
//**********************//
private void thumbFlow_DragDrop(object sender, DragEventArgs e)
{
PictureBox data = (PictureBox)e.Data.GetData(typeof(PictureBox));
FlowLayoutPanel _destination = (FlowLayoutPanel)sender;
Point p = _destination.PointToClient(new Point(e.X, e.Y));
var item = _destination.GetChildAtPoint(p);
if (item == null)
{
p.Y = p.Y - 10;
item = _destination.GetChildAtPoint(p);
}
int index = _destination.Controls.GetChildIndex(item, false);
if (index < 0)
return;
_destination.Controls.SetChildIndex(data, index);
_destination.Invalidate();
}
private void thumbFlow_DragEnter(object sender, DragEventArgs e)
{
//apply/clear highlight
foreach (Control c in thumbFlow.Controls)
{
if (c is PictureBox)
{
PictureBox thumbFrame = (PictureBox)c;
if (thumbFrame == ActiveControl)
{
thumbFrame.highlight = true;
}
else
{
((PictureBox)c).highlight = false;
}
}
}
e.Effect = DragDropEffects.Move;
if (dragDropOccurred == false)
{
dragDropOccurred = true;
}
}
//** Scroll when user drags above or below the window object **//
private void thumbFlow_DragLeave(object sender, EventArgs e)
{
int BegY_ThumbFlow = this.thumbFlow.FindForm().PointToClient(this.thumbFlow.Parent.PointToScreen(this.thumbFlow.Location)).Y;
int thumbFlowBound_Y = this.thumbFlow.Height + BegY_ThumbFlow;
int mouseY = this.thumbFlow.FindForm().PointToClient(MousePosition).Y;
while (mouseY >= thumbFlowBound_Y)
{
thumbFlow.VerticalScroll.Value = thumbFlow.VerticalScroll.Value + DRAG_DROP_SCROLL_AMT;
mouseY = thumbFlow.FindForm().PointToClient(MousePosition).Y;
thumbFlow.Refresh();
}
while (mouseY <= BegY_ThumbFlow)
{
thumbFlow.VerticalScroll.Value = thumbFlow.VerticalScroll.Value - DRAG_DROP_SCROLL_AMT;
mouseY = thumbFlow.FindForm().PointToClient(MousePosition).Y;
thumbFlow.Refresh();
}
}
An option I am looking at would be change the highLightThumb method to check if the CTRL or Shift Key is selected and not disable the highlights
if (Control.ModifierKeys != Keys.Control)
//**
if (Control.ModifierKeys != Keys.Shift)
Then change the DragDrop DragEnter Routine. Any Help would be greatly appreciated.
Here is what I ended up doing..
After the thumbnail is generated:
Now the Thumbnail Selection Code.
In the Picturebox logic, I put now have a variable titled pageIndex. it is initialized with the Page Number. The purpose of this is because as you will see later is when I spin though my objects, if I change the childindex value, it seems to occur right away and if I drag items 2,3,4 it will skip item 3 and only move item 2 & 4. So later when I rearrange the thumbs I first order by the pageIndex.
Now to the Processing of the Drag Drop.
Update the file
I would put my code in here but it really is more specific to each individual on what they plan on doing.. I basically rebuild the file and saved it.