473,399 Members | 3,038 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,399 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 2307
"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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...

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.