Search code examples
c#.netwinformsmarquee

News ticker with moving text from left to right


I am trying to make a rss news ticker which will display the text,the text need move from left to right

enter image description here

I made the the code and text is moving from left to right but after a specific time its not showing the full text,i will be adding more news from the admin pannel,each time i add the news the text is not showing after the first scroll

the below screenshot is after a specific amount of time,only a part of news is displaying enter image description here

Code used

int x = -800,y=1;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

    private void timer1_Tick(object sender, System.EventArgs e)
        {

            label1.SetBounds(x, y, 1, 1);
            x++;
            if(x>=800)
            {
                x = 4;
            }

        }

Code for reading xml

private void StartRssThread()
        {
            List<RssChannel> channels = new List<RssChannel>();
            StringBuilder mergedFeed =  new StringBuilder();
            int mh = 0;


                int ms = 0;
                if (mh < 7)
                {
                    RssFeed DaFeed = RssFeed.Read("http://shjc.ae/rss/fileName.xml");
                    RssChannel DaChannel = (RssChannel)DaFeed.Channels[0];
                    channels.Add(DaChannel);
                    mergedFeed.AppendFormat(" {0}: ", DaChannel.Title);

                    foreach (RssItem sTrm in DaChannel.Items)
                    {
                        if (ms < 10)
                        {
                            mergedFeed.AppendFormat(" {0} |", sTrm.Title);
                            ms++;
                            mh++;
                        }
                    }
                }

            string dafeed = mergedFeed.ToString();
            mergedFeed = null;
            textBox1.Invoke(new UpdateUiCallback(this.UpdateUi), new string[] { dafeed });

        }

Solution

  • You are using hard coded values for the start and max value of x. From your question I think the text in the label has a dynamic length (correct?). If the text is of dynamic length the value of x should also be dynamic.

    Also, x starts at -800. Then slowly grows to 800 and then it gets set to 4. This seems strange to me, if the first run started at -800, the second run may also need to start at -800.

    Hope this somewhat helped you. If not, please provide more details (like why you chose -800, 800 and 4).