• Помогите) Составить программу для рисования желтого квадрата в красном круге.

Ответы 1

  • using System;using System.Windows.Forms;using System.Drawing;namespace RedSquareInYellowCircle {    static class Program {        [STAThread]        static void Main() {            Application.EnableVisualStyles();            Application.SetCompatibleTextRenderingDefault(false);            Application.Run(new Form1());        }    }    public class Form1 : Form {        private System.ComponentModel.IContainer components = null;        protected override void Dispose(bool disposing) {            if (disposing && (components != null)) {                components.Dispose();            }            base.Dispose(disposing);        }        public Form1() {            InitializeComponent();        }        private void InitializeComponent() {            this.SuspendLayout();            //             // Form1            //             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);            this.Name = "Form1";            this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);            this.ResumeLayout(false);        }        private void Form1_Paint(object sender, PaintEventArgs e) {            const int radius = 100;            float a = (float)Math.Sqrt(2) * radius;            int[] center = { this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2 };            Pen pen = new Pen(Color.Black, 0);            SolidBrush sbYellow = new SolidBrush(Color.Yellow);            SolidBrush sbRed = new SolidBrush(Color.Red);            e.Graphics.FillEllipse(sbYellow, new Rectangle(center[0] - radius, center[1] - radius, 2 * radius, 2 * radius));            e.Graphics.FillRectangle(sbRed, new Rectangle(center[0] - (int)a / 2, center[1] - (int)a / 2, (int)a, (int)a));            // Освободить объекты GDI+            pen.Dispose();            sbYellow.Dispose();            sbRed.Dispose();        }    }}

     

    сделанно в 2010 студии, если вдруг проблемы с компиляцией

  • Добавить свой ответ

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years