Solitaire Style picture dragging.

S

Steve

I have an app that requires the user to drag around small images - a bit
like the solitaire app. I'm doing it through the mousedown/mouseup and
mousemove events. It works but not as smoothly as the solitaire app. Is
there another technique that I should probably be looking at. Thanks in
advance - below is how I'm currently doing it(c#).

Steve.


private void MouseDownHandler(object sender,
System.Windows.Forms.MouseEventArgs e)
{
bDrag = true;
_X = e.X;
_Y = e.Y;
}

private void MouseMoveHandler(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (bDrag)
{
((System.Windows.Forms.PictureBox) sender).Location = new
System.Drawing.Point(((System.Windows.Forms.PictureBox) sender).Left + e.X -
_X , ((System.Windows.Forms.PictureBox) sender).Top + e.Y - _Y);
}
}

private void MouseUpHandler(object sender,
System.Windows.Forms.MouseEventArgs e)
{
bDrag = false;
}
 
A

Alex Feinman [MVP]

Changing control location in CF involves significant overhead. This is why
the movement you get is not smooth. Solitair simply grabs device context for
the entire window and repaints a small bitmap (saving the screen bits under
it to be able to restore it later). Then, when the stylus is lifted, it
performs final painting (in your case a picture box can be actually
repositioned)
 
S

Steve

Thanks. This sounds a bit complicated for my newbie status. I'll try and
review the situation once I've gained more experience.


Cheers.
Steve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top