Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

move image on the screen.

Status
Not open for further replies.

dabayi

Programmer
Oct 23, 2002
10
0
0
DE
Hallo!

I need another help on how to move an image (in the art from scrolling) when this is bigger than the screen. I don't want to use a scrollbar panel or something like that but just move the image on the screen with the mouse pointer.

thanks in advance for helping.

James
 
place the image in a Panel of equal size. set your image as its background. listen for the panel's mouse up, mouse down and mouse move events. declare these variables globally:

int mx, my;
bool drag
// mouse x and y, and a drag state;

set the ints to anything, and the bool to false in the constructor, then do these things during the apropriate events:

private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e){
pxa = panel1.Location.X;
pya = panel1.Location.Y;
drag = true;
}

private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e){
drag = false;
}

private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e){
if(drag){
panel1.Location = new Point(panel1.Location.X + e.X - mxa, panel1.Location.Y + e.Y - mya);
}
}

bingo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top