我有一个使用 FlowLayoutPanel 的 WinForm 应用程序,它显示具有多个页面的 .TIFF 文件。FlowLayoutPanel 在 ThumbNails 视图中显示所有页面。
我已经实现了适用于单个项目的拖放逻辑。现在,我想更改它以允许用户选择多个缩略图(使用 CTRL 或 Shift 键)并将拖放到不同的位置。
//** 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;
}
}
}
下面是现有的拖放逻辑。
//**********************//
//** 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();
}
}
我正在查看的一个选项是更改 highLightThumb 方法以检查是否选择了 CTRL 或 Shift 键并且不禁用高光
if (Control.ModifierKeys != Keys.Control)
//**
if (Control.ModifierKeys != Keys.Shift)
然后更改 DragDrop DragEnter 例程。任何帮助将不胜感激。