Click here to Skip to main content
15,885,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to move text every 400 millesecond
when i drag the control to windows form app the application crach and vs restart here

and the application ignore breakpoints
is my code i don't know the reason


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NewsTicker
{
    public partial class UserControl1 : Control
    {
         private System.ComponentModel.Container components = null; 
        
         
        protected Timer m_Timer; // Timer for text animation.
        protected  static string sScrollText ="testApp"; // Text to be displayed 
        private static int counter = 0;
       
        private static string nCar=""; 
        public UserControl1()
        {
            m_Timer = new Timer(); 
            // Set the timer speed and properties.
            m_Timer.Interval = 400;
            m_Timer.Enabled = true;
            m_Timer.Tick += new EventHandler(this.TimerTick);
           
        }

        private void TimerTick(object sender, EventArgs e)
        {
            System.Diagnostics.Debugger.Break();
            ReadFromFile();
            Animate();
            Invalidate();
        }
       
        void Animate()
        {
            sScrollText = sScrollText.Substring(1,
                              sScrollText.Length - 1) + sScrollText.Substring(0, 1);
                
        }

       public static void  ReadFromFile()
        {
           System.Diagnostics.Debugger.Break();
            if (nCar.Equals(sScrollText) || sScrollText != "testApp")
            {

                sScrollText = File.ReadLines(@"E:\test.txt").Skip(counter).Take(1).First();

                nCar = sScrollText;
                counter++;
            }
            else
                sScrollText = sScrollText;

        }
      
      
        //protected override void OnTextChanged( EventArgs e )
        //{
        //    sScrollText = null; 
        //    base.OnTextChanged( e );
        //} 
        
        protected override void OnClick( EventArgs e )
        {
            m_Timer.Enabled ^= true; 
            base.OnClick( e );
        } 
       
        protected override void OnPaint( PaintEventArgs pe )
        {
                     
            // Draw the text string in the control.
            pe.Graphics.DrawString( sScrollText, this.Font, Brushes.Black, 0, 0 ); 
            base.OnPaint (pe); 
          
        }
    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900