2009-11-17 6 views
3

DoDragDrop 메서드를 트리거하는 ListView 컨트롤이 있습니다. DragDrop 메서드가있는 TreeView 컨트롤 인 다른 컨트롤이 있습니다. 문제는 ListView가 DoDragDrop 메서드를 시작 했음에도 불구하고 DragDrop 메서드의 sender 매개 변수가 ListView가 아니라는 것입니다. 대신, 보낸 사람 TreeView 자체입니다. 보낸 사람이 틀린 이유는 무엇입니까?C# 두 개의 다른 컨트롤 간 드래그 앤 드롭

+1

송신기 파라미터는 이벤트를 전송 제어 (즉, 트 리뷰) 누가되지 드래그 드롭을 시작으로 수행이기 때문이다. – tyranid

답변

1

아마르는

타이라니드가 언급 한 바와 같이

은 "보낸 사람"이벤트를 트리거 컨트롤입니다. 이 컨트롤은 드래그를 시작한 컨트롤이 아니라 드래그를 수락 한 컨트롤입니다.

예 :

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace WindowsFormsApplication2 
{ 
    /// <summary> 
    /// There's button 1 and button 2... button 1 is meant to start the dragging. Button 2 is meant to accept it 
    /// </summary> 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     /// <summary> 
     /// This is when button 1 starts the drag 
     /// </summary> 
     private void button1_MouseDown(object sender, MouseEventArgs e) 
     { 
      this.DoDragDrop(this, DragDropEffects.Copy); 
     } 

     /// <summary> 
     /// This is when button 2 accepts the drag 
     /// </summary> 
     private void button2_DragEnter(object sender, DragEventArgs e) 
     { 
      e.Effect = DragDropEffects.Copy; 
     } 


     /// <summary> 
     /// This is when the drop happens 
     /// </summary> 
     private void button2_DragDrop(object sender, DragEventArgs e) 
     { 
      // sender is always button2 
     } 

    } 
}