Я пытаюсь поместить текст от 0 до 11 на 12 картинок с изображением мяча, но получить текст 11 на всех.Напишите текст в массиве PictureBox
Как я могу получить текст на шарах от 0 до 11?
вот мой код:
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 wfballs2
{
public partial class Form1 : Form
{
String s;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
PictureBox[] Shapes = new PictureBox[12];
for (int i = 0; i < 12; i++)
{
s = Convert.ToString(i);
Shapes[i] = new PictureBox();
Shapes[i].Name = "ball" + i.ToString();
Shapes[i].Location = new Point(10 + 45 * i, 300);
Shapes[i].Size = new Size(40, 40);
Shapes[i].Image = Image.FromFile(@ "C:\Users\Eiko\Desktop\ball\ball.jpg");
Shapes[i].SizeMode = PictureBoxSizeMode.CenterImage;
Shapes[i].Visible = true;
this.Controls.Add(Shapes[i]);
Shapes[i].Paint += new PaintEventHandler((sender2, e2) =>
{
e2.Graphics.DrawString(s, Font, Brushes.Black, 10, 13);
});
}
}
}
}
Кроме того, я стараюсь это, но тот же результат ...... спасибо U – ej8000
Я забыл сказать, что текст стал 12 на всех шарах – ej8000
@ ej8000 неподвижного захват переменной, это работает в моем местном тесте ... – rene