2012-09-21 3 views
2

여러 페이지가있는 .TIFF 파일을 표시하는 FlowLayoutPanel을 사용하는 WinForm 응용 프로그램이 있습니다. FlowLayoutPanel은 모든 페이지를 축소판보기로 표시합니다.

개별 항목에 대해 잘 작동하는 끌어서 놓기 논리를 구현했습니다. 이제는 사용자가 여러 축소판을 선택하고 (CTRL이나 Shift 키 사용) 드래그 드롭을 다른 지점으로 드래그 할 수 있도록 변경하려고합니다.FlowLayoutPanel에서 여러 항목 끌어 놓기

//** 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(); 
    } 

} 

내가에서 찾고있는 옵션은 그 다음 끌어서 놓기의 dragEnter 루틴을 변경 하이라이트

if (Control.ModifierKeys != Keys.Control) 
//** 
if (Control.ModifierKeys != Keys.Shift) 

비활성화를 선택하려면 Ctrl 있는지 확인 또는 Shift 키를 위해 highLightThumb 방법을 변경하지 것이다. 어떤 도움이라도 대단히 감사하겠습니다. 여기

답변

1

썸네일이 생성 된 후 나는

..하고 결국 무엇을 : 이제

PictureBox thumb = new util.PictureBox(pageNum); 
thumb.Image = doc.getThumb(pageNum); //since we pre loaded, we won't stall the gui thread. 
thumb.SizeMode = PictureBoxSizeMode.CenterImage; 
thumb.BorderStyle = BorderStyle.FixedSingle; 
thumb.Click += new System.EventHandler(
    (thumbSend, thumbEvent) => 
    { 
     selectThumb(thumb); 
    } 
); 
thumb.DoubleClick += new System.EventHandler(
    (thumbSend, thumbEvent) => 
    { 
     selectedDoc = thumb.getPage(); 
     me.Visible = false; 
    } 
); 
thumbFlow.Controls.Add(thumb); 
if (selectedDoc == pageNum) 
    selectThumb(thumb); 

축소판 선택 코드입니다.
Picturebox 논리에서 이제는 pageIndex라는 변수가 있습니다. 페이지 번호로 초기화됩니다. 이것의 목적은 당신이 나중에 볼 수 있듯이 내 물건을 돌릴 때입니다, 내가 childindex 값을 변경하면, 바로 발생하는 것 같습니다. 그리고 아이템 2,3,4를 드래그하면 항목 3을 건너 뛰고 이동 만합니다. item 2 & 4. 나중에 엄지 손가락을 재배치 할 때 pageIndex로 먼저 정렬합니다.

//*************************************// 
//** Thumbnail Selection Processing **// 
//*************************************// 
/// <summary> 
/// Main Thumbnail selection area. 
/// If the Shift key is held down, look for a search between. 
/// If Ctrl key, do not clear selections as can select multiple. 
/// </summary> 
private void selectThumb(PictureBox _thumb) 
{ 
    if (Control.ModifierKeys == Keys.Shift) 
     if (SelectMultipleThumbs(_thumb.getPageIndex())) //** if another thumb is selected, select all in between, then exit **// 
      return; 

    if (Control.ModifierKeys != Keys.Control) 
    { 
     ClearAllSelections(); 
    } 
    else 
    { 
     if (_thumb.IsSelected == true) 
     { 
      _thumb.IsSelected = false; 
      return; 
     } 
    } 

    _thumb.IsSelected = true; 
} 

/// <summary> 
/// Check if there are other selected items. If there is, select all between the start and end. 
/// </summary> 
private bool SelectMultipleThumbs(int _pageindex) 
{ 
    //** Check if there are other objects that have been selected **/ 
    int? otherSelPageIndex = GetPageIndexOfThumbSelected(_pageindex); 
    if (otherSelPageIndex != null) 
    { 
     ApplySelectionBetweenStartEndPageIndex(_pageindex, Convert.ToInt32(otherSelPageIndex)); 
     return true; 
    } 
    return false; 
} 

/// <summary> 
/// Apply Selection if between start and end Pages 
/// </summary> 
private void ApplySelectionBetweenStartEndPageIndex(int _val1, int _val2) 
{ 
    int startThumb = _val1; 
    int endThumb = _val2; 
    if (_val1 > _val2) 
    { 
     startThumb = _val2; 
     endThumb = _val1; 
    } 

    foreach (PictureBox thumbFrame in thumbFlow.Controls.OfType<PictureBox>().OrderBy(si => si.pageIndex)) 
    { 
     if (isBetween(thumbFrame.getPageIndex(), startThumb, endThumb)) 
      thumbFrame.IsSelected = true; 
     else 
      thumbFrame.IsSelected = false; 
    } 
} 

/// <summary> 
/// Clear All Highlight 
/// </summary> 
private void ClearAllSelections() 
{ 
    foreach (PictureBox thumbFrame in thumbFlow.Controls.OfType<PictureBox>()) 
    { 
     thumbFrame.IsSelected = false; 
    } 
} 

/// <summary> 
/// Check for any selected items prior 
/// </summary> 
private int? GetPageIndexOfThumbSelected(int _pageindex) 
{ 
    foreach (PictureBox thumbFrame in thumbFlow.Controls.OfType<PictureBox>()) 
    { 
     if (thumbFrame.IsSelected && 
      _pageindex != thumbFrame.getPageIndex()) 
     { 
      return thumbFrame.getPageIndex(); 
     } 
    } 
    return null; 
} 

이제 드래그 드롭 처리 중입니다.

private void thumbFlow_DragDrop(object sender, DragEventArgs e) 
{ 
    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 dropIndexValue = _destination.Controls.GetChildIndex(item, false); 
    if (dropIndexValue < 0) 
     return; 

    //**************************************************// 
    //** Process multiple Select Drag/Drop 
    //** If Drag From > Drag To, move after. 
    //** If Drag From < Drag To, move before. 
    //**************************************************// 

    //** First .. Find all items that are selected **// 
    Boolean WasDragUp = false; 
    int? firstDragIndexValue = null; 
    int newIndexVal = dropIndexValue; 
    foreach (PictureBox thumbFrame in thumbFlow.Controls.OfType<PictureBox>().Where(selVal => selVal.IsSelected)) 
    { 
     if (firstDragIndexValue == null) 
     { 
      firstDragIndexValue = _destination.Controls.GetChildIndex(thumbFrame, false); 
      if (firstDragIndexValue > dropIndexValue) 
       WasDragUp = true; 
     } 
     thumbFrame.pageIndex = newIndexVal; 
     newIndexVal++; 
    } 

    //** Second .. Find all items that are NOT selected **// 
    if (WasDragUp) 
    { 
     newIndexVal = 0; 
     foreach (PictureBox thumbFrame in thumbFlow.Controls.OfType<PictureBox>().Where(selVal => !selVal.IsSelected)) 
     { 
      if (_destination.Controls.GetChildIndex(thumbFrame, false) == dropIndexValue) 
       if (newIndexVal <= dropIndexValue) 
        newIndexVal = dropIndexValue + getThumbSelectedCnt(); 
      thumbFrame.pageIndex = newIndexVal; 
      newIndexVal++; 
     } 
    } 
    else 
    { 
     newIndexVal = 0; 
     foreach (PictureBox thumbFrame in thumbFlow.Controls.OfType<PictureBox>().Where(selVal => !selVal.IsSelected)) 
     { 
      thumbFrame.pageIndex = newIndexVal; 
      if (_destination.Controls.GetChildIndex(thumbFrame, false) == dropIndexValue) 
      { 
       newIndexVal = dropIndexValue + getThumbSelectedCnt(); 
      } 
      newIndexVal++; 
     } 
    } 

    //** Third .. Set the Child Index value **// 
    newIndexVal = 0; 
    foreach (PictureBox thumbFrame in thumbFlow.Controls.OfType<PictureBox>().OrderBy(si => si.pageIndex)) 
    { 
     thumbFrame.pageIndex = newIndexVal; 
     _destination.Controls.SetChildIndex(thumbFrame, thumbFrame.pageIndex); 
     thumbFrame.IsSelected = false; 
     newIndexVal++; 
    } 

    //** Finally, rebuild the screen **// 
    _destination.Invalidate(); 

} 

private void thumbFlow_DragEnter(object sender, DragEventArgs e) 
{ 
    //apply/clear highlight 
    foreach (PictureBox thumbFrame in thumbFlow.Controls.OfType<PictureBox>()) 
    { 
     if (thumbFrame == ActiveControl) 
     { 
      thumbFrame.IsSelected = true; 
     } 
    } 

    e.Effect = DragDropEffects.Move; 
    if (dragDropOccurred == false) 
    { 
     dragDropOccurred = true; 
    } 
} 

/// <summary> 
/// Scroll when user drags above or below the window object. 
/// </summary> 
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(); 
    } 

} 

업데이트 파일

내가 여기에 내 코드를 넣어 것입니다하지만 정말 그들이 할 계획 무엇을 각 개인에게 더 고유은 .. 나는 기본적으로 파일을 다시 작성하고 저장.