Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Fishy += opperator

Fishy += opperator

Scheduled Pinned Locked Moved C#
questionhelp
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eggie5
    wrote on last edited by
    #1

    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

    A I N 3 Replies Last reply
    0
    • E eggie5

      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

      A Offline
      A Offline
      Alexander Kojevnikov
      wrote on last edited by
      #2

      eggie5 wrote: what is stopping it from re executing? This line: this.timer2.Stop(); You need to start the timer again in buttonProgress_Click. Also move this.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

      E 1 Reply Last reply
      0
      • A Alexander Kojevnikov

        eggie5 wrote: what is stopping it from re executing? This line: this.timer2.Stop(); You need to start the timer again in buttonProgress_Click. Also move this.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

        E Offline
        E Offline
        eggie5
        wrote on last edited by
        #3

        I don't understand what you want me to do with .... this.timer2.Tick += new System.EventHandler(this.timer2_Tick); /\ |_ E X E GG

        C A 2 Replies Last reply
        0
        • E eggie5

          I don't understand what you want me to do with .... this.timer2.Tick += new System.EventHandler(this.timer2_Tick); /\ |_ E X E GG

          C Offline
          C Offline
          Csharp
          wrote on last edited by
          #4

          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 :)

          C 1 Reply Last reply
          0
          • C Csharp

            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 :)

            C Offline
            C Offline
            Csharp
            wrote on last edited by
            #5

            oops lost my name for that post :| ^^^^^

            1 Reply Last reply
            0
            • E eggie5

              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

              I Offline
              I Offline
              Ista
              wrote on last edited by
              #6

              I would suggest the delegate part 2 article on this site

              1 Reply Last reply
              0
              • E eggie5

                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

                N Offline
                N Offline
                Nick Parker
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • E eggie5

                  I don't understand what you want me to do with .... this.timer2.Tick += new System.EventHandler(this.timer2_Tick); /\ |_ E X E GG

                  A Offline
                  A Offline
                  Alexander Kojevnikov
                  wrote on last edited by
                  #8

                  eggie5 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 after InitializeComponent(); Alexandre Kojevnikov MCAD charter member Leuven, Belgium

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups