Answer to Question #251923 in C# for Holik

Question #251923
122. Construct and paint a rectangle with sides of 30 and 50 pixels, the center of which is aligned with the center
screen. The sides of the rectangle must be parallel
the coordinate axes of the screen.
1
Expert's answer
2021-10-15T17:41:12-0400
namespace PaintShape
{
    partial class frmPaintShape
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // frmPaintShape
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(294, 271);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmPaintShape";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Paint Shape";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.frmPaintShape_Paint);
            this.ResumeLayout(false);

        }

        #endregion
    }
}






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace PaintShape
{
    public partial class frmPaintShape : Form
    {
        public frmPaintShape()
        {
            InitializeComponent();
        }


        private void frmPaintShape_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen pen = new Pen(Color.Red);
            const float WIDTH= 30;
            const float HEIGHT =50;
            float centerX = (this.Width / 2) - WIDTH / 2;
            float centerY = (this.Height / 2) - HEIGHT;
            g.DrawRectangle(pen, centerX, centerY, WIDTH, HEIGHT);
        }
    }
}








Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS