我有一个类“制作”,将一个矩形绘制到 Form1 类中。
问题是我必须在 form1 的不同位置再创建两个矩形,但我不知道如何在同一个类中再绘制两个矩形
制作.cs:
class Making
{
public Rectangle[] makingRec;
private SolidBrush brush;
private int x, y, width, height;
public Making()
{
makingRec = new Rectangle[7];
brush = new SolidBrush(Color.Red);
x = 50;
y = 50;
width = 10;
height = 10;
for (int i = 0; i < makingRec.Length; i++)
{
makingRec[i] = new Rectangle(x, y, width, height);
x -= 10;
}
}
public void drawMaking(Graphics paper)
{
foreach (Rectangle making in makingRec)
{
paper.FillRectangle(brush, making);
}
}}
}
Form1.cs:
public partial class Form1 : Form
{
Graphics paper;
Making making = new Making();
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
paper = e.Graphics;
making.drawMaking(paper);