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); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)