描述一下我的问题:
我的winform窗体有52个picturebox,这些picturebox里的图片依次发生变化时(例如用一张图片替换当前图片),窗体不会立刻显示这一变化,而是在所有picturebox的图片都更替完毕后,显示最后的效果,而我想要的是,在每一次变化时picturebox就及时做出变化,我最先在每一步更替操作后加上refresh()刷新窗体,确实可以实现这一要求,但是问题来了,这个操作是刷新整个winform窗体,在大量图片更替时,refresh一直被执行,导致窗体卡住无法操作。请问还有哪些方法可以解决这些问题?
附上代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace poke_text
{
public partial class Form1 : Form
{
PictureBox[] pb;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int Num = 0;
Num = 53;
pb = new PictureBox[Num];
for (int i = 1; i < Num; i++)
{
pb[i] = new System.Windows.Forms.PictureBox();
pb[i].BorderStyle = BorderStyle.FixedSingle;
pb[i].Height = 100;
pb[i].Width = 50;
pb[i].Image = Image.FromFile(@"C:\Users\Administrator\source\repos\poke_text\poke_text\bin\Resources\" + i + ".JPG");
pb[i].SizeMode = PictureBoxSizeMode.StretchImage;
flowLayoutPanel1.Controls.Add(pb[i]);
}
}
private void button2_Click(object sender, EventArgs e)
{
int a = 2;
int count = 52;
while (a < 53)
{
int[] b = new int[52];
for (int i = 0; i < 52; i += 1)
{
b[i] = 0;
}
for (a = 2; a < 53; a += 1)
{
for (int temp = a; temp < 53; temp += 1)
{
if (temp % a == 0)
{
if (b[temp - 1] == 0)
{
pb[temp].Image = Image.FromFile(@"C:\Users\Administrator\source\repos\poke_text\poke_text\bin\Resources\back.JPG");
count--;
refresh();
//这里的刷新窗体
b[temp - 1] = 1;
}
else
{
pb[temp].Image = Image.FromFile(@"C:\Users\Administrator\source\repos\poke_text\poke_text\bin\Resources\" + temp + ".JPG");
count++;
b[temp - 1] = 0;
}
}
}
}
string s1 = count.ToString();
string s2 = Convert.ToString(count);
textBox1.Text = s2;
}
}
}
}