D
David J Rose
I am having trouble allowing a user to drag an item, whilst also allowing
them to click the item. I am using mousedown, mousemove and mouseup. It
works if I click the button carefully, but if there is any mouse movement,
then it is interpreted as a drag, and the click does not work. What I want
is a way to only do the drag if the mouse movement is above a threshold. Is
this possible?
Here is the basic code:
private void ItemToolStripButton_MouseDown(object sender, MouseEventArgs e)
{
ToolStripButton btn = ((ToolStripButton)sender);
if (e.Button == MouseButtons.Right)
{
//show contextmenu
}
else
{
bMouseDown = true;
}
}
private void ItemToolStripButton_MouseMove(object sender, MouseEventArgs e)
{
if ((bMouseDown) && (e.Button == MouseButtons.Left))
{
ToolStripButton btn = ((ToolStripButton)sender);
btn.DoDragDrop(btn.Tag, DragDropEffects.Copy);
}
}
}
private void ItemToolStripButton_MouseUp(object sender, MouseEventArgs e)
{
ToolStripButton btn = ((ToolStripButton)sender);
if (e.Button != MouseButtons.Right)
{
//perform the onclick code here
bMouseDown = false;
}
Much Thanks
them to click the item. I am using mousedown, mousemove and mouseup. It
works if I click the button carefully, but if there is any mouse movement,
then it is interpreted as a drag, and the click does not work. What I want
is a way to only do the drag if the mouse movement is above a threshold. Is
this possible?
Here is the basic code:
private void ItemToolStripButton_MouseDown(object sender, MouseEventArgs e)
{
ToolStripButton btn = ((ToolStripButton)sender);
if (e.Button == MouseButtons.Right)
{
//show contextmenu
}
else
{
bMouseDown = true;
}
}
private void ItemToolStripButton_MouseMove(object sender, MouseEventArgs e)
{
if ((bMouseDown) && (e.Button == MouseButtons.Left))
{
ToolStripButton btn = ((ToolStripButton)sender);
btn.DoDragDrop(btn.Tag, DragDropEffects.Copy);
}
}
}
private void ItemToolStripButton_MouseUp(object sender, MouseEventArgs e)
{
ToolStripButton btn = ((ToolStripButton)sender);
if (e.Button != MouseButtons.Right)
{
//perform the onclick code here
bMouseDown = false;
}
Much Thanks