Results 1 to 12 of 12

Thread: call procedure from timer_tick

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    39

    call procedure from timer_tick

    Hi,

    I have some code that I have been using to move linklabel's to the left by 1px per timer ticker. The problem I have is once all the linklabels have moved fully to the left I would like to call a procedure that will distroy all the linklabels and reload them from an updated feed.

    The issue I am having is that I can't workout how to do this using this code
    Code:
            private void timer1_Tick(object sender, EventArgs e)
            {
                for (int i = 0; i < lblArray.Count; i++)
                {
                    lblArray[i].Left -= 1; // move to the left 1 pixel per tick
                    // each title cycling on panel from right to left 
    
                    if (lblArray[i == 0 ? lblArray.Count - 1 : i - 1].Right == this.panel1.Width && lblArray[i].Right < 0)
                    {
                        lblArray[i].Left = this.panel1.Width;
                    }
                }
            }
    Can someone please help me to amend this code (or recreate this effect) to enable me to call a procedure and if anyone can suggest a better process than distroying the linklabels and recreating them then that would be fantastic!

    Thanks for your time.

    Al

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: call procedure from timer_tick

    Code:
    		private void timer1_Tick(object sender, System.EventArgs e)
    		{
    			for (int i = 0; i < lblArray.Length; i++)
    			{
    				lblArray[i].Left -= 1; // move to the left 1 pixel per tick
    				// each title cycling on panel from right to left 
    
    				if (lblArray[i].Location.X == 0)
    				{
    					lblArray[i].Left = this.panel1.Width;
    				}
    			}
    		}

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    39

    Re: call procedure from timer_tick

    Quote Originally Posted by wild_bill
    Code:
    		private void timer1_Tick(object sender, System.EventArgs e)
    		{
    			for (int i = 0; i < lblArray.Length; i++)
    			{
    				lblArray[i].Left -= 1; // move to the left 1 pixel per tick
    				// each title cycling on panel from right to left 
    
    				if (lblArray[i].Location.X == 0)
    				{
    					lblArray[i].Left = this.panel1.Width;
    				}
    			}
    		}
    Where do I place the call to a procedure?

    reload();

    Al

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: call procedure from timer_tick

    Code:
    		private void timer1_Tick(object sender, System.EventArgs e)
    		{
    			for (int i = 0; i < lblArray.Length; i++)
    			{
    				lblArray[i].Left -= 1; // move to the left 1 pixel per tick
    				// each title cycling on panel from right to left 
    
    				if (lblArray[i].Location.X == 0)
    				{
    				       //Uncomment the next line if you need to
                                           //lblArray[i].Left = this.panel1.Width;
                                           reload();
    				}
    			}
    		}

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    39

    Re: call procedure from timer_tick

    Quote Originally Posted by mendhak
    Code:
    		private void timer1_Tick(object sender, System.EventArgs e)
    		{
    			for (int i = 0; i < lblArray.Length; i++)
    			{
    				lblArray[i].Left -= 1; // move to the left 1 pixel per tick
    				// each title cycling on panel from right to left 
    
    				if (lblArray[i].Location.X == 0)
    				{
    				       //Uncomment the next line if you need to
                                           //lblArray[i].Left = this.panel1.Width;
                                           reload();
    				}
    			}
    		}
    wild_bill, mendhak,

    that code generates an error - Error 'WindowsApplication5.LinkLabelArray' does not contain a definition for 'Length'.

    Is there any solution to this?

    Thanks,

    Al

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: call procedure from timer_tick

    That's an example of why it's a bad idea to call something a name that doesn't describe what it is. You called it an array so they assumed it was an array. It's not an arry though, it's a collection. The Length was trying to get the number of items and the property to do that with a collection is Count, which you've already used so you knew that. If you try to understand what they're getting at you can probbaly fix it if it doesn't work. Also, if your LinkLabelArray class is a collection, not an array, then it should be called LinkLabelCollection.
    Last edited by jmcilhinney; Sep 29th, 2006 at 03:26 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    39

    Re: call procedure from timer_tick

    Quote Originally Posted by jmcilhinney
    That's an example of why it's a bad idea to call something a name that doesn't describe what it is. You called it an array so they assumed it was an array. It's not an arry though, it's a collection. The Length was trying to get the number of items and the property to do that with a collection is Count, which you've already used so you knew that. If you try to understand what they're getting at you can probbaly fix it if it doesn't work. Also, if your LinkLabelArray class is a collection, not an array, then it should be called LinkLabelCollection.

    I will change the name, I had left it for the time being am still testing this functionality in a dummy project.

    The code works once I changed .Lenght to .Count but the final (i hope) issue is that the code executes the procedure call once the first linklabel has moved fully to the left. But what I need to do is allow all the current linklabels move to the left and then call the procedure. Do you have any idea's how I can allow this to happen?

    I was thinking if I know how many items where within the collection I could then count the items and once the last item has completed, this can then call the procedure.

    Thanks,

    Al

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: call procedure from timer_tick

    Absolutely. Store the total in a variable and each time one of the labels gets to the left you decrement it. Once it reaches zero you know that all labels have made the trip.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    39

    Re: call procedure from timer_tick

    Hi,

    I am able to store the total amount of items into a variable (thats easy!) and I have been trying to work out how I can sucessfully count down till the last linklabel has been shown and once thats happened carryout a call for my procedure.

    I have been playing around with this:
    Code:
            private void timer1_Tick(object sender, System.EventArgs e)
            {
                for (int i = 0; i < lblArray.Count; i++)
                {
                    lblArray[i].Left -= 1;
    
                    if (lblArray[i].Location.X == 0)
                    {
                        //Uncomment the next line if you need to
                        //lblArray[i].Left = this.panel1.Width;
                        //reload();
                        if (i == rssItems)
                        { MessageBox.Show("reload rss"); }
                    }
                }
            }
    I have used the MessageBox control so I know that something has happened. The problem is that the messagebox never shows even though all the linklabels move of the screen.

    Can someone help me out please? And also am I going about doing this in the correct mannor?

    jmcilhinney was mentioning counting down the linklabels and once they reach zero do the procedure call but I can't get that working either.

    Many thanks,

    Al

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: call procedure from timer_tick

    You've got a collection of labels. That's good because you can remove at will. I would suggest that in your Tick event handler you loop through the collection and move each label, then test its location. If it is all the way to the left then you remove it from the collection and destroy it. Once you've moved all the labels you test the collection to see if it still contains any labels. If it doesn't then you know it's time to start again. Note that as you're removing items from the collection you must loop backewards, i.e. instead of going from zero to the end you go from the end to zero.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    39

    Re: call procedure from timer_tick

    Quote Originally Posted by jmcilhinney
    You've got a collection of labels. That's good because you can remove at will. I would suggest that in your Tick event handler you loop through the collection and move each label, then test its location. If it is all the way to the left then you remove it from the collection and destroy it. Once you've moved all the labels you test the collection to see if it still contains any labels. If it doesn't then you know it's time to start again. Note that as you're removing items from the collection you must loop backewards, i.e. instead of going from zero to the end you go from the end to zero.
    Hi jmcilhinney and everyone else,

    Does the LinkLabelCollection add the new items to the collection in fisrt position. So really the first linklabel added is in the last postion on the collection?

    I think I need to create a statement that says if the the itemCount is >= 1 then if the lblCollection[i].Right < 0 then distroy the item depending on the itemCount value either do the following:

    <= 0 Reload entire RSS feed or if >= 1 then do nothing

    I hope that all makes sense?

    Thanks,

    Al

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: call procedure from timer_tick

    No, heh. Didn't make sense to me at least. What exactly is .Right<0 ?

    Also, the items are added to the 'end' of the collection, not at the beginning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width