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

  • Home
  • SEARCH
  • 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 3845840
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:18:21+00:00 2026-05-19T16:18:21+00:00

I am attempting to drag a shape around a picturebox on the mousemove event

  • 0

I am attempting to drag a shape around a picturebox on the mousemove event but am struggling to get it to move smoothly. The picture box has an image loaded as the background and I would like the graphics object to drag a circle on top of the image when the mouse is clicked and dragged.

I have it working by creating a clone of the original image each time the mouse moves and reloading the picture box but it seems like their must be a better way to achieve this.

Without reloading the original bitmap each time any graphics added remain on the image creating a trail which is more like a paint application.

How do I clear previous drawings without reloading the entire image each time? Any help appreciated.

private void picCanvas_MouseMove(object sender, MouseEventArgs e)
{
    if (_drag)
    {
        picCanvas.Image = (Bitmap)_original.Clone();
        Graphics g = Graphics.FromImage((Bitmap)picCanvas.Image);
        g.DrawEllipse(_whitePen, e.X, e.Y, 10, 10);
        picCanvas.Invalidate();
    }
}

private void picCanvas_MouseDown(object sender, MouseEventArgs e)
{
    _drag = true;
}

private void picCanvas_MouseUp(object sender, MouseEventArgs e)
{
    _drag = false;
}
  • 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-05-19T16:18:21+00:00Added an answer on May 19, 2026 at 4:18 pm

    To solve the problem in the best way, use picCanvas.Paint event.
    Set the positions at mousemove event and use that positions to draw at paint event.

        Point pos = Point.Empty;// or your initial position
    
        private void picCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (_drag)
            {
                pos = e.Location;
            }
        }
        private void picCanvas_Paint(object sender, PaintEventArgs e)
        {
            if (_drag)
            {
                Graphics g = e.Graphics;//The event handler sends us the graphics object to use for painting
                g.DrawEllipse(_whitePen, pos.X, pos.Y, 10, 10); 
            }
        }
    

    You should add the Paint event to the Control and set the image at formload or some initialization function.

    picCanvas.Image = (Bitmap)_original.Clone(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting/struggling to get registration and sign-up working within an active admin project. I have
Attempting to build a C# project which has numerous references to assemblies in NuGet
Attempting to test whether a post has a 'main_slider', 'flickr-slider', or 'video-slider' value. 'main_slider'
I'm attempting to add the ability to drag and drop to reorder some boxes
Attempting to move an uploaded file so that it is saved in the directory,
Attempting to learn CI and going through the docs to get a better understanding.
Attempting to get an answer to this question. How can I turn off the
Attempting to get LocationUpdates in my Service, however, it doesnt ever seem to fire
I'm attempting to allow my users to drag and drop certain rows of data
I'm attempting to upload a file via drag and drop with HTML5. The dragging

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.