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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:34:17+00:00 2026-06-07T08:34:17+00:00

I am just trying to draw a rectangle on mouse move event . I

  • 0

I am just trying to draw a rectangle on mouse move event . I just saved the starting point in MouseDown Event and Ending Point is from Mouse Move . And called the paintImage Function .

Rectangle rec = new Rectangle (x1,y1,x2 - x1 , y2 - y1);
G.DrawRectangle(Pens.Blue,rec);

Starting Points = (x1,y1)
Ending Points = (x2,y2)

The Problem is When the value of x2 is less than x1 OR y2 is less than y1 the rectangle is not drawing … Anyone help me on this

  • 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-07T08:34:20+00:00Added an answer on June 7, 2026 at 8:34 am

    You could easily write a check:

    int drawX, drawY, width, height;
    if (x1 < x2)
    {
        drawX = x1;
        width = x2 - x1;
    }
    else
    {
        drawX = x2;
        width = x1 - x2;
    }
    
    if (y1 < y2)
    {
        drawY = y1;
        height = y2 - y1;
    }
    else
    {
        drawY = y2;
        height = y1 - y2;
    }
    
    Rectangle rec = new Rectangle (drawX, drawY, width, height);
    G.DrawRectangle(Pens.Blue,rec);
    

    This can also be written in shorter form:

    Rectangle rec = new Rectangle ((x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, (x1 < x2) ? x2 - x1 : x1 - x2, (y1 < y2) ? y2 - y1 : y1 - y2);
    G.DrawRectangle(Pens.Blue,rec);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to just draw a Rectangle on a PictureBox that is on
I'm trying to just draw a simple image from the drawable-mdpi folder in android
i am trying to draw a rectangle when i press mouse left button and
trying to draw a random number from a distribution in SciPy, just like you
I'm just trying to draw a line with JavaScript. I would like it to
I am trying to draw a textured cube using just 8 vertices and one
I've moved on from trying to use OpenGL through Penumbra to trying to draw
So I'm trying to draw a simple rectangle in my iOS cocos2d game, but
i'm trying to draw a rectangle with semi-circles at either end. i'm also trying
I am trying to draw a rectangle and let the user create it based

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.