Fishy += opperator
-
Check this out...
private void buttonProgress\_Click(object sender, System.EventArgs e) { string byteFile2=this.textBoxActiveData.Text; this.timer2.Tick += new System.EventHandler(this.timer2\_Tick); FileInfo myFileInfo = new FileInfo(byteFile2); long lSize = myFileInfo.Length; string gNiggas=lSize.ToString(); seconds=lSize/350; }
on the Event Handler line, what is the
+=
doing? here is what it is calling...protected void timer2\_Tick (object sender, System.EventArgs e) { this.timer2.Start(); int f=1; int p=1; for(f=1; f<20; f++) { p++; if(f==19) { f=200; this.timer2.Stop(); MessageBox.Show(f.ToString()); } progressBar.Value=p; } //MessageBox.Show("END OF PROGRESS BAR"); progressBar.Value=0; }
anyways... the problem is... I can run the timer2_Tick once. But when I click on the button again it won't go... what is stopping it from re executing? /\ |_ E X E GG
-
Check this out...
private void buttonProgress\_Click(object sender, System.EventArgs e) { string byteFile2=this.textBoxActiveData.Text; this.timer2.Tick += new System.EventHandler(this.timer2\_Tick); FileInfo myFileInfo = new FileInfo(byteFile2); long lSize = myFileInfo.Length; string gNiggas=lSize.ToString(); seconds=lSize/350; }
on the Event Handler line, what is the
+=
doing? here is what it is calling...protected void timer2\_Tick (object sender, System.EventArgs e) { this.timer2.Start(); int f=1; int p=1; for(f=1; f<20; f++) { p++; if(f==19) { f=200; this.timer2.Stop(); MessageBox.Show(f.ToString()); } progressBar.Value=p; } //MessageBox.Show("END OF PROGRESS BAR"); progressBar.Value=0; }
anyways... the problem is... I can run the timer2_Tick once. But when I click on the button again it won't go... what is stopping it from re executing? /\ |_ E X E GG
eggie5 wrote: what is stopping it from re executing? This line:
this.timer2.Stop();
You need to start the timer again inbuttonProgress_Click
. Also movethis.timer2.Tick += new System.EventHandler(this.timer2_Tick);
line to the constructor or any place where it will run only once. Alexandre Kojevnikov MCAD charter member Leuven, Belgium -
eggie5 wrote: what is stopping it from re executing? This line:
this.timer2.Stop();
You need to start the timer again inbuttonProgress_Click
. Also movethis.timer2.Tick += new System.EventHandler(this.timer2_Tick);
line to the constructor or any place where it will run only once. Alexandre Kojevnikov MCAD charter member Leuven, Belgium -
I don't understand what you want me to do with ....
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
/\ |_ E X E GG -
you need to put :
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
in an area like the "#region Windows Form Designer generated code" is what Alexandre was trying to say. then the timer will always work when you click the button :) -
Check this out...
private void buttonProgress\_Click(object sender, System.EventArgs e) { string byteFile2=this.textBoxActiveData.Text; this.timer2.Tick += new System.EventHandler(this.timer2\_Tick); FileInfo myFileInfo = new FileInfo(byteFile2); long lSize = myFileInfo.Length; string gNiggas=lSize.ToString(); seconds=lSize/350; }
on the Event Handler line, what is the
+=
doing? here is what it is calling...protected void timer2\_Tick (object sender, System.EventArgs e) { this.timer2.Start(); int f=1; int p=1; for(f=1; f<20; f++) { p++; if(f==19) { f=200; this.timer2.Stop(); MessageBox.Show(f.ToString()); } progressBar.Value=p; } //MessageBox.Show("END OF PROGRESS BAR"); progressBar.Value=0; }
anyways... the problem is... I can run the timer2_Tick once. But when I click on the button again it won't go... what is stopping it from re executing? /\ |_ E X E GG
-
Check this out...
private void buttonProgress\_Click(object sender, System.EventArgs e) { string byteFile2=this.textBoxActiveData.Text; this.timer2.Tick += new System.EventHandler(this.timer2\_Tick); FileInfo myFileInfo = new FileInfo(byteFile2); long lSize = myFileInfo.Length; string gNiggas=lSize.ToString(); seconds=lSize/350; }
on the Event Handler line, what is the
+=
doing? here is what it is calling...protected void timer2\_Tick (object sender, System.EventArgs e) { this.timer2.Start(); int f=1; int p=1; for(f=1; f<20; f++) { p++; if(f==19) { f=200; this.timer2.Stop(); MessageBox.Show(f.ToString()); } progressBar.Value=p; } //MessageBox.Show("END OF PROGRESS BAR"); progressBar.Value=0; }
anyways... the problem is... I can run the timer2_Tick once. But when I click on the button again it won't go... what is stopping it from re executing? /\ |_ E X E GG
eggie5 wrote: on the Event Handler line, what is the += doing? The idea between events and delegates here is that when your timers tick event is fired you want to register a new method to be called, hence a callback function which is defined under .NET as a delegate. Essentially there is a linked list of functions that allow you to either
+=
add or-=
remove delegates from the chain. You should probably just specify the event/delegate within your constructor code, there is no reason to re-register this everytime. -Nick Parker -
I don't understand what you want me to do with ....
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
/\ |_ E X E GGeggie5 wrote: I don't understand what you want me to do with ....
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
Move it to the constructor, just afterInitializeComponent();
Alexandre Kojevnikov MCAD charter member Leuven, Belgium