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 9256503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:57:29+00:00 2026-06-18T11:57:29+00:00

In the last few months I’ve been working on an application, and one of

  • 0

In the last few months I’ve been working on an application, and one of it’s functions is that it can crop images. So, I’ve coded a function that draws a transparent orange rectangle, to show the user the crop area, but it works very slowly – can anyone help me/show me a way to make it faster?

Here is the code:

Image source;

private void pictureBox1_MouseDown(object sender, MouseEventArgs e) {
    mousePos = e.Location;
}

Point mousePos;

private void pictureBox1_MouseMove(object sender, MouseEventArgs e) {
    if (e.Button == MouseButtons.Left) {
        Image editSource = new Bitmap(source);
        Graphics g = Graphics.FromImage(editSource);
        SolidBrush brush = new SolidBrush(
            Color.FromArgb(128, Color.Orange.R, Color.Orange.G, Color.Orange.B));

        int width = e.X - mousePos.X;
        if (width < 0) {
            width *= -1;
        }

        int height = e.Y - mousePos.Y;
        if (height < 0) {
            height *= -1;
        }

        Size cropRectSize = new Size(width, height);
        Rectangle cropRect = new Rectangle(mousePos, cropRectSize);
        g.FillRectangle(brush, cropRect);
        pictureBox1.Image = editSource;
    }
}
  • 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-18T11:57:31+00:00Added an answer on June 18, 2026 at 11:57 am

    So, all recommendations for not using picture box aside… I’ll give you a method to doing it 😉

    The idea behind this is to only use mouse move, mouse down, etc to store what should be drawn. Then when it’s time to draw it use the stored state. This draws an orange rectangle whenever you have the mouse depressed on the picture box (even though recommendation is to not use picture box this same approach can be used for other surfaces.).

        Point startPoint;
        Point currentPoint;
        bool draw = false;
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            startPoint = e.Location;
            draw = true;
        }
    
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            draw = false;
        }
    
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            currentPoint = e.Location;
            pictureBox1.Invalidate();
        }
    
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            if (draw)
            {
                int startX = Math.Min(startPoint.X, currentPoint.X);
                int startY = Math.Min(startPoint.Y, currentPoint.Y);
                int endX = Math.Max(startPoint.X, currentPoint.X);
                int endY = Math.Max(startPoint.Y, currentPoint.Y);
                e.Graphics.DrawRectangle(Pens.Orange, new Rectangle(startX, startY, endX-startX, endY-startY));
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been spending the last few months on developing a (my first) Rails application
I have been developing an application over the last few months using EF code
I have been working on Test Automation from last few months and have been
I've been working to a C++/CLI project in the last few months. Now I'm
I've been developing an iPhone app for the last few months. Recently I wanted
Over the last few months, there have been a number of rapid developments in
Selenium 2 has been in beta phase for last few months. I would like
I've been using Eclipse only for Python over the last few months, and I'd
The last few months I've been using Emacs extensively as my main development environment
In last few months I have been making a transition from Java to Groovy

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.