IT Community - Software Programming, Web Development and Technical Support

Move an image within a picture box in C#

This is a discussion on Move an image within a picture box in C# within the C# Programming forums, part of the Software Development category; How to move an image within a picturebox in C#?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 01-16-2008, 04:18 AM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Smile Move an image within a picture box in C#

How to move an image within a picturebox in C#?
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-18-2008, 10:36 PM
it.wily it.wily is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
it.wily is on a distinguished road
Smile Re: Move an image within a picture box in C#

you cant move an image inside a picture box, instead of that you can place a picturebox in a panel and move the pictuebox with the image loaded in it. This can be done by changing the top and left positions of the picturebox..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-18-2008, 11:26 PM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Smile Re: Move an image within a picture box in C#

Can you tell me how to move the picture box inside the panel?
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-18-2008, 11:38 PM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Cool Re: Move an image within a picture box in C#

Place a picturebox in a panel such that the picture box and the panel are in the same size. Load an image in the picturebox. In the picturebox mousedown event store the x and y positions of the mouse pointer.

Quote:
private Rectangle rect;
private bool move = false;

private void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
move = true;
rect.X = e.X;
rect.Y = e.Y;
}
Then, in mouse move event, subtract the previous x,y position with the current x,y position of the mouse pointer and assign the subtracted value to the picturebox left and top position. This is done only when the move value is true.

Quote:
private void pictureBox_MouseMove(object sender, MouseEventArgs e)
{
if (move)
{
pictureBox.Left += e.X - rect.X;
pictureBox.Top += e.Y - rect.Y;
}
}
In mouse up event, change the move value to false to avoid moving the picturebox even after the mouse up event otherwise the picturebox will move when ur mouse pointer moves.

Quote:
private void pictureBox_MouseUp(object sender, MouseEventArgs e)
{
move = false;
}
Try this!!!
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-18-2008, 11:42 PM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Smile Re: Move an image within a picture box in C#

Great yaar.. nice explanation.. thanks.............
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can we move an image programmatically in pocket pc without flickering using C#? mobilegeek Mobile Software Development 3 04-23-2008 09:17 PM
server move Booom Discussweb HQ 1 02-10-2008 02:58 AM
Help-How to move a Flex project seesamjagan Adobe Flex Programming 0 01-03-2008 01:19 AM
What is the length(picture clause)? S.Vinothkumar Database Support 1 10-30-2007 01:17 AM
How to Move a database in SQL 2000 to 2005 ? nnraja Server Management 2 10-29-2007 01:08 AM


All times are GMT -7. The time now is 05:14 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0