Bug when drawing rectangles in my Paint Program

前端 未结 1 700
闹比i
闹比i 2021-01-28 12:01
public partial class Form1 : Form
{
    Point downPoint , upPoint;
    List shapes = new List();
    public ShapesEnum shapeType;

    public         


        
相关标签:
1条回答
  • 2021-01-28 12:35

    Try something like this in order to have the start and end points the right way:

    int x0 = Math.Min(upPoint.X, downPoint.X);
    int y0 = Math.Min(upPoint.Y, downPoint.Y);
    Point upperLeft = new Point(x0, y0);
    
    int x1 = Math.Max(upPoint.X, downPoint.X);
    int y1 = Math.Max(upPoint.Y, downPoint.Y);
    Point lowerRight = new Point(x1, y1);
    

    And

    Rectangle rect = new Rectangle(x0, y0, x1 - x0, y1 - y0);
    
    0 讨论(0)
提交回复
热议问题