2013-03-12 1 views
2

DragDrop 이벤트가 발생한 후에 드래그 된 toolStrip의 항목을 확인하는 방법을 찾고 있습니다. 원하는 작업은 도구 상자의 각 항목마다 다른 경우로 전환하는 것입니다. 하지만 나는 그들을 비교하는 방법을 찾는 것 같습니다.C# DragDrop from toolStrip

UPDATE : SHORT CODESAMPLE

private void toolStrip1_DragDrop(object sender, DragEventArgs e) 
{ 
    //Here I want something like a DoDragDrop() and send the specific item from the 
    //toolstrip.. 
} 

private void panel1_MouseUp(object sender, MouseEventArgs e) 
{ 
    //And here some way to determine which of the items was dragged 
    //(I'm not completely sure if I need a mouseUp event though..) 
} 

잘하면 좀 더 쉽게 내가 할 노력하고있어 얻을 수 있습니다.

+0

당신은 무엇을 시도 : 여기

는 2 ToolStripButtons이있는 ToolStrip에서 동작하는 예제입니다? http://mattgemmell.com/2008/12/08/what-have-you-tried/ –

+0

UI 컨트롤과 같은 참조 유형에서는 전환을 수행 할 수 없습니다. if/else if/else를 수행해야합니다. 핸들러에서 코드를 제공하고 UI가 정의 된 곳 (.designer 파일)을 제공하면 더 많은 도움이 될 수 있습니다. –

+0

코드 샘플은 모두 2 개의 버튼이있는 도구 막대이고 빈 패널이기 때문에 코드 샘플이 필요하다고 생각하지 않았습니다. 내가 원하는 것은 툴 스트립에서 패널로 무엇인가 드래그 한 다음 툴 스트립의 어떤 아이템이 드래그 되었는가를 결정할 때 dragdrop 이벤트를 발생시키는 것입니다. 현재는 단지 2 개의 버튼입니다 만, 나는 단지 그것을 비교할 방법이 있다고 가정 할 수 있습니다. 스트립에있는 버튼의 텍스트, 그리고 각 버튼의 스위치 케이스와 같은 것을 원한다. – Jacco

답변

3

예제의 이벤트가 올바른 이벤트로 보이지 않습니다.

public Form1() { 
    InitializeComponent(); 
    toolStripButton1.MouseDown += toolStripButton_MouseDown; 
    toolStripButton2.MouseDown += toolStripButton_MouseDown; 

    panel1.DragEnter += panel1_DragEnter; 
    panel1.DragDrop += panel1_DragDrop; 
} 

void toolStripButton_MouseDown(object sender, MouseEventArgs e) { 
    this.DoDragDrop(sender, DragDropEffects.Copy); 
} 

void panel1_DragEnter(object sender, DragEventArgs e) { 
    e.Effect = DragDropEffects.Copy; 
} 

void panel1_DragDrop(object sender, DragEventArgs e) { 
    ToolStripButton button = e.Data.GetData(typeof(ToolStripButton)) 
          as ToolStripButton; 
    if (button != null) { 
    if (button.Equals(toolStripButton1)) { 
     MessageBox.Show("Dragged and dropped Button 1"); 
    } else if (button.Equals(toolStripButton2)) { 
     MessageBox.Show("Dragged and dropped Button 2"); 
    } 
    } 
} 
+0

고마워요! 의도 한대로 완벽하게 작동합니다. – Jacco