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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:07:07+00:00 2026-05-20T12:07:07+00:00

Hi I would do the selected area to cut an image on picturebox control.

  • 0

Hi I would do the selected area to cut an image on picturebox control.

I have the following code:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{

public partial class Form1 : Form
{
    private Rectangle rect;
    private Pen p;

    public Form1()
    {
        InitializeComponent();
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        if (this.p == null)
            this.p = new Pen(Color.FromArgb(100, 200, 200, 200), 5);
        if (this.rect.Width > 0)
            e.Graphics.DrawRectangle(this.p, this.rect);
    }

    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {

        if (e.X < this.rect.X)
        {
            this.rect.Width = this.rect.X - e.X;
            this.rect.X = e.X;
        }
        else
        {
            this.rect.Width = e.X - this.rect.X;
        }

        if (e.Y < this.rect.Y)
        {
            this.rect.Height = this.rect.Y - e.Y;
            this.rect.Y = e.Y;
        }
        else
        {
            this.rect.Height = e.Y - this.rect.Y;
        }

        this.Invalidate(this.rect);

    }

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        this.rect.X = e.X;
        this.rect.Y = e.Y;
    }

}

}

It returns an error here:

Application.Run(new Form1());

Why?

thanks for all replies ;p

  • 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-20T12:07:08+00:00Added an answer on May 20, 2026 at 12:07 pm

    Try using this optimized code, if you still get error post it here (edit your original question) and we’ll see.

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
       if (this.p == nulll)
          this.p = new Pen(Color.FromArgb(100, 200, 200, 200), 5);
       if (this.rect.Width > 0)
          e.Graphics.DrawRectangle(this.p, this.rect);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two XmlDocuments and I would like to move an XmlNode selected from
Would it be possible to show an image in full screen mode using silverlight.
Would the following SQL remove also the index - or does it have to
I am using C# windows Forms in visual studio 2010. I need to know
Would OCR Software be able to reliably translate an image such as the following
I have this problem on my payroll processing system. Below the area where the
I would like to remove selected commit log entries from a linear commit tree,
How would you go about producing reports by user selected date ranges in a
Is there a way to vertically stack selected td elments? I would like to
Would it be possible to print Hello twice using single condition ? if condition

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.