我的问题如下: 我有一个计时器,每 1 毫秒我想加载一个图像并以 win 形式将其显示在一个图片框中 第一个图像工作得很好,但是从某个点开始图像开始加载困难。你能告诉我如何解决这个问题吗?
问候并感谢您的宝贵时间:)
private string path = "";
private int index = 0;
private void fileSourceToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ofd.ShowDialog() == DialogResult.OK)
{
string fullPath = ofd.FileName;
string fileName = ofd.SafeFileName;
path = fullPath.Replace(fileName, "");
MessageBox.Show("Path for file source has been selected");
}
}
private const string IMAGENAME = "TestImage";
Bitmap b;
private void timer_Tick(object sender, EventArgs e)
{
try
{
string currentImage = IMAGENAME + index.ToString() + ".bmp";
index++;
b = new Bitmap(path + "\\" + currentImage);
pb.SizeMode = PictureBoxSizeMode.StretchImage;
pb.Image = b;
}
catch { };
}
private void button1_Click(object sender, EventArgs e)
{
timer.Start();
}
private void button2_Click(object sender, EventArgs e)
{
timer.Stop();
}
private void button3_Click(object sender, EventArgs e)
{
try
{
string currentImage = IMAGENAME + index.ToString() + ".bmp";
index += 1;
Bitmap b = new Bitmap(path + "\\" + currentImage);
pb.Image = b;
}
catch { };
}
private void button4_Click(object sender, EventArgs e)
{
try
{
index -= 1;
string currentImage = IMAGENAME + index.ToString() + ".bmp";
Bitmap b = new Bitmap(path + "\\" + currentImage);
pb.Image = b;
}
catch { };
}