473,473 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

implementing dragdrop whilst allowing click

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

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 17 '05 #1
6 6641
"David J Rose" <da********@newsgroup.reply.only.com> wrote in message
news:42**********@spool9-west.superfeed.net...
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?


There's a whole bunch of events, such as

DragDrop
DragEnter
DragLeave
DragOver
ItemDrag

that you need to set up. In addition, there is a property called AllowDrop
that needs to be turned on. Using these things the system will initiate and
do the drag and drop operation for you.

-- Alan
Nov 17 '05 #2
I believe that all the events mentioned are for accepting a dragged item. I
am talking about starting the drag-drop operation using the DoDragDrop
method.

Any more ideas?
"Alan Pretre" <al********@newsgroup.nospam> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
"David J Rose" <da********@newsgroup.reply.only.com> wrote in message
news:42**********@spool9-west.superfeed.net...
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?


There's a whole bunch of events, such as

DragDrop
DragEnter
DragLeave
DragOver
ItemDrag

that you need to set up. In addition, there is a property called
AllowDrop that needs to be turned on. Using these things the system will
initiate and do the drag and drop operation for you.

-- Alan


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 17 '05 #3
"David J Rose" <da********@newsgroup.reply.only.com> wrote in message
news:42**********@spool9-west.superfeed.net...
I believe that all the events mentioned are for accepting a dragged item. I
am talking about starting the drag-drop operation using the DoDragDrop
method.


Sorry, I guess I should have asked you where you are dragging from. If you
are dragging from a listview or a treeview, you do the DoDragDrop() call in
the ItemDrag event, not MouseDown.

-- Alan
Nov 17 '05 #4
David J Rose wrote:
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?
Its sort of kludgy but you could define your threshhold (say 200ms) and
start a timer in the mousedown event which when fired would do the
dragdrop only if the mouse is still down.

Havent tried though, I have had the same sort of problem with other tree
views, spec. infragistics activetree in vb6.

JB

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

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Nov 17 '05 #5
I'm facing the same problem as David is. I have a series of radio buttons
that look like regular buttons. Originally they were just designed to select
a different option. But now I want to add Drag & Drop capability so that
their order can be changed.

My first thought was to immediately back out of the MouseDown event (which
initiates Drag & Drop) if the radioButton wasn't already checked. That works
okay but isn't exactly the effect I'd ideally like.

So I'd love to get more feedback on here if the timer suggestion is the
preferred approach to resolve this issue ... or are there other approaches?

--
Robert W.
Vancouver, BC
www.mwtech.com

"John B" wrote:
David J Rose wrote:
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?


Its sort of kludgy but you could define your threshhold (say 200ms) and
start a timer in the mousedown event which when fired would do the
dragdrop only if the mouse is still down.

Havent tried though, I have had the same sort of problem with other tree
views, spec. infragistics activetree in vb6.

JB

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

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Nov 17 '05 #6
I want to follow up with what John B wrote (and thank him!) for quickly
finding me a solution to this problem.

First, I googled for: c# timer mousedown
and found this article:
http://www.informit.com/articles/art...seqNum=21&rl=1

I quickly grasped the leapfrogging the author was suggesting, along with
stopping the timer if the mouse button is released quickly enough. Here's
the code I wrote for my application, which are a series of Question buttons.
Hopefully this code can help others too:
// Initiate a dedicated timer. If the user holds down the mouse long
enough then we'll assume he wants to drag & drop.
private void QuestionButton_MouseDown(object sender, MouseEventArgs e)
{
ClickedQuestionButton = sender; // Store a reference to this
button because 'QuestionButtonTimer_Tick' can't access it otherwise
questionButtonTimer.Enabled = true;
}

// ... Otherwise if he lets go quickly then we'll assume he just wants
to click the question button instead.
private void QuestionButton_MouseUp(object sender, MouseEventArgs e)
{
questionButtonTimer.Enabled = false;
ClickedQuestionButton = null; // Just cleaning up
}

// Initiates drag & drop visual effects
private void QuestionButtonTimer_Tick(object sender, EventArgs e)
{
questionButtonTimer.Enabled = false;

QuestionButton qBut = ClickedQuestionButton as QuestionButton;
ClickedQuestionButton = null; // Just cleaning up
qBut.DoDragDrop(qBut, DragDropEffects.All);
}
In my case, it's imperative to know which QuestionButton (of several) is
being dragged, so that's why I created a module-level private variable to
temporarily store it. I don't think it's necessary to set this variable to
null but I thought it was cleaner this way.

For now I'm going to take John B's advice and use 200ms as the delay time.
I suppose that it might be prudent to allow this value to be shortened or
lengthened depending on a user's preference.

--
Robert W.
Vancouver, BC
www.mwtech.com

"Robert W." wrote:
I'm facing the same problem as David is. I have a series of radio buttons
that look like regular buttons. Originally they were just designed to select
a different option. But now I want to add Drag & Drop capability so that
their order can be changed.

My first thought was to immediately back out of the MouseDown event (which
initiates Drag & Drop) if the radioButton wasn't already checked. That works
okay but isn't exactly the effect I'd ideally like.

So I'd love to get more feedback on here if the timer suggestion is the
preferred approach to resolve this issue ... or are there other approaches?

--
Robert W.
Vancouver, BC
www.mwtech.com


Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Kate | last post by:
Hi: I have a form with a picture box and some command buttons to make certain shapes appear in the picture box. The shapes are drawn on blank UserControls added like this: 'at top of form...
1
by: KS | last post by:
In want to visualy drag a Button to a Label and when I depress the mousebutton on top of the label I want to show some dato from the Button in a MsgBox - that's my primary goal. I have made a...
4
by: Owe Armandt | last post by:
When I play with DragDrop of files to a form I get two DragEnter events before the DragDrop event, why is this?? Owe
0
by: Flack | last post by:
Hello, Is it possible to find out how many methods are listening to a certain event? For example, if a number of methods subscribed to a controls DragDrop event using +=, can I find out how many...
0
by: Sarika | last post by:
Hello all, I have a MDI form w/ a treeview. A splitter control separates the treeview part of the form from the MDI client. (MDI Client is placed on the MDI parent). The client form has a panel...
3
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the...
9
by: jon | last post by:
Hello, I'm trying to experiment with some javascript to do some custom dragdrop handling. I wish to use the onMouseDown event to trigger the start of my drag, and onMouseup for a potentential...
10
by: Jonathan | last post by:
Hi all, I have a file consisting fixed width records from which I need to extract only those lines meeting certain conditions. These conditions do change and I find myself recoding/compiling...
5
by: OHM \( One Handed Man \) | last post by:
Is it possible to have visual studio add the stubs for you when you implement an interface or inherit from a an abstract class automatically. I know this was a feature in vb.net but I can seem to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.