Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:27:08+00:00 2026-06-18T05:27:08+00:00

I want to move a pictureBox using my mouse so I got till here:

  • 0

I want to move a pictureBox using my mouse so I got till here:

    private void pictureB_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawImage(image, recLoc);
    }
    private void pictureB_MouseDown(object sender, MouseEventArgs e)
    {
        WorkAble = true;
        choosingPoint.X = e.X;
        choosingPoint.Y = e.Y; 
        lastPoint.X = e.X;
        lastPoint.Y = e.Y;
    }

    private void pictureB_MouseMove(object sender, MouseEventArgs e)
    {
        if (WorkAble)
        {
            recLoc.X = e.X - choosingPoint.X;// + lastPoint.X;
            recLoc.Y = e.Y - choosingPoint.Y;// + lastPoint.Y;
            pictureB.Refresh();
        }
    }

    private void pictureB_MouseUp(object sender, MouseEventArgs e)
    {
        WorkAble = false;
        lastPoint.X = e.X;
        lastPoint.Y = e.Y;
    }
    // recLoc = pictureBox Location.

well, it works great.. However not perfectly..
What I mean is once the KeyUp event is executed, and you click again the image will return to the 0, 0 point of the pictureBox.
To overcome that I added the lastPoint point and in the mouse move I add its values.
So in the one hand it does draw the image in the last dropped point, however the mouse will be on the 0, 0 point of to the image and not in the place I clicked – on the image. Like if I click on the center of the image the mouse will be on the 0, 0 point..

any suggestions how to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:27:10+00:00Added an answer on June 18, 2026 at 5:27 am

    Make incremental changes to “recLoc” to avoid losing the original location:

    private void pictureB_MouseMove(object sender, MouseEventArgs e)
    {
        if (WorkAble)
        {
            recLoc.X = recLoc.X + e.X - choosingPoint.X;
            recLoc.Y = recLoc.Y + e.Y - choosingPoint.Y;
            choosingPoint = e.Location;
            pictureB.Invalidate();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display graphic file in PictureBox I have: private void btnLoad_Click(object sender,
This is the code in the NumericUpDown ValueChanged event: private void numericUpDown1_ValueChanged(object sender, EventArgs
boolean f=0; timer1.Interval=1; private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e) { if (f == 0)
I want to move cells just as these two methods do: - (void)tableView:(UITableView *)tableView
i want to move a table to a new filegroup. Using the accepted answer
I want to move a part, i.e. one subdirectory of an existing, private mercurial
I want to move some file to other place, using Java SE 1.6 So,
i want move up the object, delay 1000ms , then hide it, i get
I want to move image from one location in excel to another using VBA.
I want to Move pencil image using UITouch? I want to move pencil and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.