Answer to Question #251924 in C# for Holik

Question #251924
.
123. Construct and paint a circle with a radius of 40 pixels,
the center of which is aligned with the center of the screen.
1
Expert's answer
2021-10-15T17:41:14-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 RADIUS = 40;
            float centerX = (this.Width / 2) - RADIUS/2;
            float centerY=(this.Height / 2) - RADIUS;
            g.DrawEllipse(pen,centerX, centerY, RADIUS, RADIUS);
        }
    }
}






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