2017-12-10 26 views
0

목록 상자 안에 일부 텍스트를 드래그하는 동안 일부 키로 드래그 효과를 변경해야합니다 (&).컨트롤 위로 개체를 끌 때 키 상태를 잡는 방법은 무엇입니까? - C#

bool ctrlD = false; 

private void MainForm_KeyDown(object sender, KeyEventArgs e) 
{ 
    if (e.Control && e.KeyCode == Keys.D) 
     ctrlD = true; 
} 

// KeyUp 

private void textBox_MouseDown(object sender, MouseEventArgs e) 
{ 
    textBox.DoDragDrop(textBox.Text, DragDropEffects.All); 
} 

private void listBox_DragOver(object sender, DragEventArgs e) 
{ 
    if (ctrlD) e.Effect = DragDropEffects.Copy; 
    else e.Effect = DragDropEffects.Move; 
} 

키를 누를 때 DragOver 메서드가 표시되지 않는 문제가 있습니다. 효과는 변하지 않습니다. 이 일을 어떻게 할 수 있습니까?

+0

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.querycontinuedrag(v=vs.110).aspx –

+0

@Hans 옆모습 난 아직 할 수 없습니다 커서 효과를 변경하는 방법을 이해합니다. QueryContinueDrag가 도움이되지 않습니다. –

답변

0
bool ctrlD = false 

를 사용하여 개체를 보낸 사람

private void textBox_MouseDown(object sender, MouseEventArgs e) 
{ 
    if (e.Button == MouseButtons.Left) 
    { 
     this.DoDragDrop(sender, DragDropEffects.All); 
    } 
} 

진정한

추가 (MyContol) (_DragEnter) 및 (_DragDrop) 이벤트

을에 AllowDrop의를 설정해야합니다
private void MyControl_DragEnter(object sender, DragEventArgs e) 
{ 
    /* 
    DragDropEffects 
    */ 
    e.Effect = DragDropEffects.Copy; 
} 

private void MyControl_DragDrop(object sender, DragEventArgs e) 
{ 
    TextBox tb = e.Data.GetData(typeof(TextBox)) as TextBox; 
    /* 
    MyControl.Controls.Add(tb); 
    * Your code here 
    */ 
} 
+0

이렇게해도 문제가 해결되지 않습니다. –