写一段C#程序,将70个pictureBox控件名称pictureBox1~70画成70个红色圆,并将70个圆围成一个圆圈
时间: 2024-11-25 09:20:46 浏览: 15
在C#中,你可以使用Windows Forms的PictureBox控件和Graphics类来创建这种效果。首先,你需要一个Form窗口,并在这个窗口上添加70个PictureBox控件。下面是一个简化的示例代码,用于设置PictureBox控件为红色圆形并按照圆环排列:
```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
// 创建PictureBox数组
PictureBox[] pictureBoxes = new PictureBox[70];
int x = 50; // 初始x坐标
int y = 50; // 初始y坐标
int radius = 40; // 圆形半径
int spacing = 60; // 控件之间的间距
for (int i = 1; i <= 70; i++)
{
// 创建PictureBox控件并设置名称
pictureBoxes[i - 1] = new PictureBox();
pictureBoxes[i - 1].Name = $"pictureBox{i}";
pictureBoxes[i - 1].Size = new Size(radius * 2, radius * 2);
pictureBoxes[i - 1].Location = new Point(x, y);
// 设置背景颜色为红色
pictureBoxes[i - 1].BackgroundImage = new Bitmap(pictureBoxes[i - 1].Width, pictureBoxes[i - 1].Height, PixelFormat.Format32bppArgb);
using (SolidBrush brush = new SolidBrush(Color.Red))
Graphics.FromImage(pictureBoxes[i - 1].BackgroundImage).DrawEllipse(brush, 0, 0, pictureBoxes[i - 1].Width, pictureBoxes[i - 1].Height);
// 将PictureBox添加到Form中
Controls.Add(pictureBoxes[i - 1]);
// 更新下一个位置,形成圆环状排列
x += spacing + radius;
if (x + radius > ClientSize.Width)
{
x = 50;
y += spacing + radius;
}
}
}
}
//
阅读全文