0

In my form load I have this:

private void PrintingDesignForm_Load(object sender, System.EventArgs e) {
        int formWidth = this.Width; //300
        int formHeight = this.Height; //300

        decimal rectWidth = 1000;
        decimal rectHeight = 800;

        // Code to scale down rectangle

        this.Paint += (se, pe) => {
            var r = new Rectangle(0, 0, (int)Math.Floor(rectWidth), (int)Math.Floor(rectHeight));

            var brush = new SolidBrush(Color.FromArgb(255, 255, 204));

            pe.Graphics.FillRectangle(brush, r);
            using (var pen = new Pen(brush.Color, 2))
                pe.Graphics.DrawRectangle(pen, r);
        };
    }

I am trying to resize my rectangle so it will fit the form size in proportion to the rectangle size.

How can I do this?

Andrew
  • 720
  • 3
  • 9
  • 34
  • You can calculate height and width to automatically fit `form` size is one way to do it. – P. Pat May 11 '17 at 01:02
  • 1
    hmm .. just change the form `.BackColor` – Slai May 11 '17 at 01:05
  • @Slai How would this solve anything? – Andrew May 11 '17 at 01:07
  • by changing the form "rectangle" color without needing rectangle? Maybe screenshot would make it clearer, because I don't get the point of the rectangle – Slai May 11 '17 at 01:09
  • Your rectangle is equivalent to the image in the marked duplicate. The basic idea is identical: you need to calculate new dimensions, taking into account the current aspect ratio, selecting one dimension that will be identical to the fitted area (depending on your goals...you will either fit the entire rectangle in the target space, or you will size the rectangle so it completely fills the target space...in your example, I'm guessing the former), and calculate the other based on the aspect ratio. – Peter Duniho May 11 '17 at 01:45

0 Answers0