Why would MouseDown event fire DragEnter and DragDrop?

Apr 19 2010 9:35 PM

I am attempting to do a 'Drag & Drop + Swap' in a small piece of code to allow a user to swap some text across two TextBox(es) (at the end of the Drop). Clearly a very simple task but for some reason a simple MouseDown event ends up firing the associated DragEnter and DragDrop events. Therefore if I just click on one of the two TextBoxes in question, all three events are executed. Anyone know why this would occur? I see nothing in any doc that indicates this is normal behavior, looks like a bug. I am using VS 2008 C#. My problem is that I have code to add to the DragEnter and DragDrop event handlers that I don't want executed when the user inadvertently MouseClicks on one of the textboxes (MouseClick starts with MouseDown event which seems to be processed ahead of a handler for MouseClick). Code is as follows:

 

private void tb_DragEnter(object sender, DragEventArgs e)

{

if (e.Data.GetDataPresent(typeof(String)))

{

e.Effect = DragDropEffects.Move;

}

else

{

e.Effect = DragDropEffects.None;

}

}

private void tb_MouseDown(object sender, MouseEventArgs e)

{

TextBox source = (TextBox)sender;

DoDragDrop(source.Text, DragDropEffects.Move);

}

private void tb_DragDrop(object sender, DragEventArgs e)

TextBox destination = (TextBox)sender;

destination.Text = (String)e.Data.GetData(typeof(String));

}


Answers (1)