Here’s the code for my ListBox MouseMove event:
private void lbxItems_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) //this one is good
{
lbxItems.DoDragDrop("Copy Text 1", DragDropEffects.Copy);
}
else if (Control.ModifierKeys == Keys.Alt && e.Button == MouseButtons.Left) //this desn't work
{
lbxItems.DoDragDrop("Copy Text 2", DragDropEffects.Copy);
}
}
The e.Button == MouseButtons.Left condition alone works okay, but not with Control.ModifierKeys == Keys.Alt. I wonder if the ListBox control can recognize ALT key + Left Mousebutton combination. Can anyone suggest please?
Hmm, well, I think I found a fix here, which is pretty easy.
To make it work, I just need to evaluate the
Control.ModifierKeys == Keys.Altcondition first and pute.Button == MouseButtons.Leftin theelse ifstatement. Thus, ALT + Left Mousebutton will always be checked first.Also, I have to point out that it’s not
Control.ModifierKeys == Keys.Altdidn’t work, just the original code never got chance to runelse ifstatement.