Answer the question
In order to leave comments, you need to log in
How to implement repetition of shapes in the corners?
Hello. I need to implement the drawing of a square with repeating squares at the corners.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Lab4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void DrawRectangles(Graphics g, Pen pen, Point startPoint, Size size)
{
if (size.Width < 40 || size.Height < 40) return;
startPoint.Offset(-size.Width / 2, -size.Height / 2);
var rect = new Rectangle(startPoint, size);
g.DrawRectangle(pen, rect);
var newSize = new Size(size.Width / 2, size.Height / 2);
var points = new List<Point>
{
startPoint,
new Point(startPoint.X + size.Width, startPoint.Y),
new Point(startPoint.X, startPoint.Y + size.Height),
new Point(startPoint.X + size.Width, startPoint.Y + size.Height)
};
points.ForEach(pt =>
{
DrawRectangles(g, pen, pt, newSize);
});
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
var pen = new Pen(Color.Black, 3);
var startPoint = new Point(0, 0);
startPoint.Offset(Width / 2, Height / 2);
var size = new Size(Height / 2, Height / 2);
DrawRectangles(e.Graphics, pen, startPoint, size);
}
private void Form1_SizeChanged(object sender, EventArgs e)
{
Refresh();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
Application.Exit();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question