Reputation: 113
In Form1 i have label2 in the designer and i added a code:
public void lbl2(string text)
{
label2.Text = text;
}
In the new class top i added:
private static AnimationEditor.Form1 fr1 = new AnimationEditor.Form1();
And in the new class event im updating the label2.Text like this:
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;
}
Thel ine that is doing the updating is:
fr1.lbl2(_frameId.ToString();
Now i used breakpoint on this line in the new class and also in Form1 on the label2.Text in the public function and i saw that the label2 text is changing first its 0 then 1 then 2 and so on.
But in fact in realtime when im running the application the label2 dosent change its all the time the text saty as label2
This is the Form1 button click event when i click on it its doing the new class code:
private void button5_Click(object sender, EventArgs e)
{
wmv = new Polkan.DataSource.WmvAdapter(@"d:\VIDEO0040.3gp", sf);
wmv.SaveToDisc = true;
wmv.Start();
wmv.WaitUntilDone();
}
Upvotes: 1
Views: 531
Reputation: 81675
I think the quick answer is to pass in the reference of the label to the class:
private Label lbl;
public WmvAdapter(string file, string outFolder, Label label) {
// yada-yada-yada
lbl = label;
}
Your routine would change to:
if (File.Exists(tempFile))
{
lbl.Text = _frameId.ToString();
}
Your click event:
private void button5_Click(object sender, EventArgs e)
{
wmv = new Polkan.DataSource.WmvAdapter(@"d:\VIDEO0040.3gp", sf, this.Label2);
wmv.SaveToDisc = true;
wmv.Start();
wmv.WaitUntilDone();
}
The longer answer is to have your class raise an event and have your form listen for it.
Having your class be aware of the form is not the best coding practice.
Upvotes: 1