如果我一键单击离开箭头键,然后单击并再次离开,等等图像都变好了。但是,如果我不停地按右箭头键,则只有当我将右箭头键留在它停止的位置时,图像才会改变,以便加载此 trackBar 值中的图像。
这是我的滚动事件:
private void trackBar1_Scroll(object sender, EventArgs e)
{
currentFrameIndex = trackBar1.Value;
textBox1.Text = "Frame Number : " + trackBar1.Value;
wireObject1.woc.Set(wireObjectAnimation1.GetFrame(currentFrameIndex));
LoadPictureAt(trackBar1.Value, sender);
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button8.Enabled = false;
SaveFormPicutreBoxToBitMapIncludingDrawings();
return;
}
到目前为止,我还没有 trackBar 的其他事件。
这是 LoadPictureAt 函数:
private bool LoadPictureAt(int nIndex, object c)
{
bool bRet = false;
if (nIndex >= 0 && nIndex < fi.Length)
{
if (c.Equals(trackBar1))
pictureBox1.Load(fi[nIndex].FullName);
bRet = true;
}
return bRet;
}
我解决了:
我在滚动事件之前添加了一个新功能:
private void setpicture(int indx)
{
if (fi == null)
{
}
else
{
if (indx >= 0 && indx <= trackBar1.Maximum && fi.Length > indx)
{
try
{
label19.ForeColor = Color.Red;
fileToolStripMenuItem.Enabled = true;
label19.Visible = false;
label20.Visible = false;
label14.Visible = true;
label15.Visible = true;
label8.Visible = true;
label9.Visible = true;
trackBar1.Enabled = true;
using (FileStream fs = new FileStream(fi[indx].FullName, FileMode.Open))
{
this.label8.Visible = true;
this.label9.Visible = true;
this.label9.Text = fi[indx].Name;
Image img = null;
Bitmap bmp = null;
Image imgOLd = null;
try
{
img = Image.FromStream(fs);
bmp = new Bitmap(img);
imgOLd = this.pictureBox1.Image;
this.pictureBox1.Image = bmp;
if (imgOLd != null)
imgOLd.Dispose();
img.Dispose();
img = null;
}
catch
{
if (img != null)
img.Dispose();
if (bmp != null)
bmp.Dispose();
if (imgOLd != null)
imgOLd.Dispose();
}
}
}
catch
{
}
}
else
{
Image imgOLd = this.pictureBox1.Image;
if (imgOLd != null)
{
imgOLd.Dispose();
imgOLd = null;
}
Application.DoEvents();
}
}
}
并将滚动事件更改为:
private void trackBar1_Scroll(object sender, EventArgs e)
{
currentFrameIndex = trackBar1.Value;
textBox1.Text = "Frame Number : " + trackBar1.Value;
wireObject1.woc.Set(wireObjectAnimation1.GetFrame(currentFrameIndex));
trackBar1.Minimum = 0;
trackBar1.Maximum = fi.Length - 1;
setpicture(trackBar1.Value);
pictureBox1.Refresh();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button8.Enabled = false;
SaveFormPicutreBoxToBitMapIncludingDrawings();
return;
}