Quote:
Originally Posted by ProDielerNR(1)
hat mir leider nicht geholfen :?
um es spezifischer zu beschreiben, ich möchte mit der mouse die pickbox hin und her verschieben auf einer bestimmten x axe (kordinaten)
|
I don't know much vb sintax, but here is the basic algorithm:
1- Register mouse down event either for form or picture itself
1.a- Inside event handler save click location in a global or accesible variable in your code named $prevMousePosition, set $movingX and $movingY variables to false or sth like that, and set $mouseDown to true
2-Register mouse move event in form
2.a - if(not $mouseDown) return; //exit function nothing to do here
2.b - Compute $prevMousePosition vs $currentMouse if $movingX or $movingY are false, something like this:
if(not movingX and not movingY){
dx = $currentMouse.X - $prevMousePosition.X
dy = $currentMouse.Y - $prevMousePosition.Y
if(dx > dy)
$movingX = true
else
$movingY = true
}
if($movingX){
//lock x axis to click location in Y
Picturebox1.location = ($currentMouse.X,$prevMousePosition.Y)
}else if($movingY){
Picturebox1.location = ($prevMousePosition.X,$currentMouse.Y)
}
3- Register mouse up event: clear $mouseDown flag and set it to false
Reference for mouse events
Notes: words with $ means variables, just to clarify.
Summary:
Code:
mouseDownEvent(_,event){
movingX = false;
movingY = false;
prevMousePosition = event;
mouseDown = true;
}
mouseUpEvent(_,event){
mouseDown = false;
}
mouseMoveEvent(_,event){
if(not mouseDown) return;
f(not movingX and not movingY){
dx = event.X - prevMousePosition.X
dy = event.Y - prevMousePosition.Y
if(dx > dy)
movingX = true
else
movingY = true
}
if(movingX){
//lock x axis to click location in Y
Picturebox1.location = (event.X,prevMousePosition.Y)
}else if($movingY){
Picturebox1.location = (prevMousePosition.X,event.Y)
}
}
You can expand this code saving the object that you clicked in a variable and updating location of saved object