【发布时间】:2012-06-15 20:31:09
【问题描述】:
在 Form1 中,我在设计器中有 label2,我添加了一个代码:
public void lbl2(string text)
{
label2.Text = text;
}
在我添加的新班级顶部:
private static AnimationEditor.Form1 fr1 = new AnimationEditor.Form1();
在新的类事件中,我像这样更新 label2.Text:
int ISampleGrabberCB.BufferCB(double sampleTime, IntPtr pBuffer, int bufferLen)
{
using (var bitmap = new Bitmap(_width, _height, _width * 3, PixelFormat.Format24bppRgb, pBuffer))
{
bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
if (SaveToDisc)
{
String tempFile = _outFolder + _frameId + ".bmp";
if (File.Exists(tempFile))
{
fr1.lbl2(_frameId.ToString();
}
else
{
bitmap.Save(Path.Combine(_outFolder, _frameId + ".bmp"));
}
_frameId++;
}
else
{
if (Images == null)
Images = new List<Bitmap>();
Images.Add((Bitmap)bitmap.Clone());
}
}
return 0;
}
正在更新的线路是:
fr1.lbl2(_frameId.ToString();
现在我在新类中的这一行以及公共函数的 label2.Text 的 Form1 中使用了断点,我看到 label2 文本首先更改它的 0,然后是 1,然后是 2,依此类推。
但实际上,当我实时运行应用程序时,label2 会一直将其更改为 label2 的文本
这是 Form1 按钮单击事件,当我单击它时,它会执行新的类代码:
private void button5_Click(object sender, EventArgs e)
{
wmv = new Polkan.DataSource.WmvAdapter(@"d:\VIDEO0040.3gp", sf);
wmv.SaveToDisc = true;
wmv.Start();
wmv.WaitUntilDone();
}
【问题讨论】:
-
用户界面被锁定是什么意思?在 Form1 中不更新其他标签,例如在 picturebox1 鼠标移动事件中,我在标签 1 中更新鼠标移动的坐标及其工作。我还尝试在运行时代码中将 label2 文本更改为“hi”以进行测试,它确实有效。所以这里穿的是别的东西。
-
fr1不需要是您正在使用的表单的实际引用吗?我看到fr1 = new AnimationEditor.Form1();,这可能不是您使用的表单的同一个实例。 -
LarsTech AnimationEditor 是命名空间。我在 label2.Text = text; 行上使用了一个断点。在 Form1 的 lbl2 函数中,看到文本已更改。变量文本正在改变 0,1,2....
-
当然可以。看起来您有两种形式:一种是您正在使用的,另一种是您的班级创建的。不同的东西。
-
LarsTech 我现在还在 Form1 lbl2 函数中的 label2.Text = text 上使用了一个断点,并且看到文本也在发生变化,而且 label2.Text 也在变化,一旦它的 0 然后 1 然后 2.. .等等...mmmm
标签: c#