473,323 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Handling cursor drag

I need an event handler for dragging the cursor on a PictureBox. The
existing events only include handlers for dragging and dropping objects over
the controls. I'm trying to use the MouseDown and MouseUp handlers as below,
but it never gets out of the while loop.

this.PicBox.MouseDown += new MouseEventHandler(this.StartMapDrag);
this.PicBox.MouseUp += new MouseEventHandler(this.EndMapDrag);

private void StartMapDrag(object sender, MouseEventArgs e)
{
drag = true;
WhileDrag();
}

private void EndMapDrag(object sender, MouseEventArgs e)
{
drag = false;
}

private void WhileDrag()
{
while (drag)
{
// Do something here
}
}

Can someone tell me a better way to handle this event?
Jon Cosby
Nov 16 '05 #1
1 2299
"Jon Cosby" <jc****@nospam.net> wrote in
news:7k*****************@newsread2.news.pas.earthl ink.net:
I need an event handler for dragging the cursor on a PictureBox. The
existing events only include handlers for dragging and dropping objects
over the controls. I'm trying to use the MouseDown and MouseUp handlers
as below, but it never gets out of the while loop.

this.PicBox.MouseDown += new MouseEventHandler(this.StartMapDrag);
this.PicBox.MouseUp += new MouseEventHandler(this.EndMapDrag);

private void StartMapDrag(object sender, MouseEventArgs e)
{
drag = true;
WhileDrag();
}

private void EndMapDrag(object sender, MouseEventArgs e)
{
drag = false;
}

private void WhileDrag()
{
while (drag)
{
// Do something here
}
}

Can someone tell me a better way to handle this event?


The gui is single threaded. This means that the gui's process is
executing the WhileDrag while loop and is never doing something else. You
could opt for an Application.DoEvents() in teh while(drag) loop, as that
would handle all messages currently stored at the message pump and for
example would hten call a mouse handler routine.

Drag and drop however is not something you should babysit. Drag &
Drop starts when a user selects something and moves the mouse while
keeping the lmb down. All you then have to monitor is when teh mouse
button is released. If that's the case inside your window (f.e. in a
picture box) you have to check if a drag & drop action is going on. If so,
do a copy action for example, of the selected item(s) which were selected
when the drag started.

FB

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #2

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

Similar topics

3
by: Csaba2000 | last post by:
I have set onmousedown to change the cursor, but this setting is ignored (IE 5.5; NN 6.1 on Win 2K Pro) until the mouse is either moved or the mouse button is released. On Opera 7.01, the setting...
1
by: Jon Cosby | last post by:
I need an event handler for dragging the cursor on a PictureBox. The existing events only include handlers for dragging and dropping objects over the controls. I'm trying to use the MouseDown and...
2
by: John Dann | last post by:
This question has arisen from an earlier thread but is really a separate issue: I have a VB.Net listbox control on a form. I want to be able to do 2 things with items displayed within the one...
4
by: **Developer** | last post by:
I have a Listbox application. I allow users to drag items from one spot in the listbox to another spot. I also allow them to drag to, say, WordPad In the DoDragDrop I use DragDropEffects.Copy so...
0
by: haegens | last post by:
I am making a .NET Application which has a TreeView Control in it. I have 3 levels of nodes. The toplevel is a rootnode which contains all other nodes. The second level holds one kind of nodes that...
1
by: kallol | last post by:
Hi Everyone, I have a form designed with a table and the table is inside a <div> (Required. Can’t get rid of it). The div has style “height: 100% and scrollable: auto”. The issue: In IE, let...
2
by: Doug | last post by:
Hi I am trying to find a way to make the mouse cursor move to the keyboard cursor position in an application. For example, I use an application called Enterprise Guide, and I control this...
1
by: sCryptKeeper | last post by:
I'm trying to change the cursor while a drag and drop occurs between two lists in a winforms. I tried several ways (several tutorial and solutions) found over the web. I even tried to simply...
0
by: nagarjunt | last post by:
Hi, This is nag. I have a problem with infragistics7.1 UltraTextEditor control. I am using C# code in windows form. I have UltraTextEditor control(With multi line enabled) in my Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.