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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:01:14+00:00 2026-06-01T23:01:14+00:00

I have a program in C# (Windows Forms) which has a rectangle on a

  • 0

I have a program in C# (Windows Forms) which has a rectangle on a Picture Box. They can be drawn at an angle too (rotated). I want to rotate that rectangle using my mouse movements.

I have the code for moving that rectangle

Rectangle areaRect = new Rectangle(100,100, 300, 300);
Bool dragging = false;
Point ptOld = new Point(0, 0);

protected override void OnPaint(PaintEventArgs e)
{
  Graphics dcPaint = e.Graphics;
  dcPaint.DrawRectangle(rectPen, areaRect);
}

protected override void OnMouseDown(MouseEventArgs e)
{
  ptOld = new Point(e.X, e.Y);
  dragging = true;
}

protected override void OnMouseMove(MouseEventArgs e)
{
  if(dragging = true) 
  {
    Point ptNew = new Point(e.X, e.Y);
    int dx = ptNew.X - ptOld.X;
    int dy = ptNew.Y - ptOld.Y;
    areaRect.Offset(dx, dy); // This one moves the rectangle 
    ptOld = ptNew;
    this.Invalidate();
  }
}

protected override void OnMouseUp(MouseEventArgs e)
{
  dragging = false;
}

Now My requirement is to rotate this rectangle, Any idea, how that can be achieved.

  • 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-01T23:01:17+00:00Added an answer on June 1, 2026 at 11:01 pm

    I think you want to calculate angle between two points on X-axis. If so, try the following code:

    const double Rad2Deg = 180.0 / Math.PI;
    
    return Math.Atan2(ptOld.Y - e.Y, e.X - ptOld.X) * Rad2Deg;
    

    Also check out this article on calculating angle between two points

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which displays an image to the windows form, and places
I have created a program with Windows Forms in C# and the architecture is
I'm having problem when running my Windows Forms program. In the program, I have
I have a program written in VB 2010 express under windows xp which does
Hi I have to design a Windows Form which has a simple textbox. The
I have a solution which consists, to put it simply, a Windows Forms Application
I was testing on a customer's box this afternoon which has Windows Vista (He
I have a .NET 2.0 windows forms app, which makes heavy use of the
I have a c++/windows program that receives data from another c++ program via a
I have a network C++ program in Windows that I'd like to test for

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.