c# - Moving Picturebox on a Grid is inaccurate because Mouse Positions are inaccurate -


i have application put pictureboxes on panel. after implemented drag&drop pictureboxes, wanted add grid option conviniently move pictureboxes on panel. code used is

private void pb14_mousemove(object sender, mouseeventargs e)     {         if (e.button == mousebuttons.left)         {             if (grid)             {                 if (mouseposition.x % 10 == 0)                 {                     pblist[14].location = new point(plist[parent].pointtoclient(new point(mouseposition.x, mouseposition.y)).x, pblist[14].location.y);                 }                 if (mouseposition.y % 10 == 0)                 {                     pblist[14].location = new point(pblist[14].location.x, plist[parent].pointtoclient(new point(mouseposition.x, mouseposition.y)).y);                 }             }             else             {                 ...             }         }     } 

plist list of panels, plist[parent] parent in picturebox (out of pictureboxlist) pblist[14] is.

the problem picturebox not smoothely moving, doesnt move @ all. found out values % operation better worse, example if put

if (mouseposition.x % 30 == 0) 

in if statement, worse 10.

i put values of if() in labels , saw skip calculation, means value jumped 9 1, skipping pixel should 0 , picturebox didnt move.

do know better ways of calculating mouse coordinates purpose?

you'll want determine closest pixel of grid pixels mouse position.

pblist[14].location = new point(plist[parent].pointtoclient(new point(mouseposition.x - (mouseposition.x % 10) + 5, mouseposition.y - (mouseposition.y % 10) + 5)).x); 

although confusion setting in here required parameters pointtoclient.

the jist of is, recalculate position each mouse move regardless of whether directly on 'grid 10s', assign location if different last (to save resources on re-painting) , find closest 'grid 10s' position subracting co-ords remainder of 10 co-ord


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -