how to scroll the contents of a text file
-
The followin code scrolls the text file contents, for a single line entry. how can i scroll the contents (in a single line) if i have more than one line in my text file ???? My main aim is to make a scrolling news application, by giving the input through a text file !!! plz help ---mist--- ------------------------------------------------------------------------------------------------------ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace WindowsApplication1 { public partial class FormMain : Form { Timer timer; public FormMain() { InitializeComponent(); this.DoubleBuffered = true; } private void FormMain_Load(object sender, EventArgs e) { Streamreader re = File.Opentext("C://test.txt"); string input=null; while((input=re.ReadLine()) !=null) { label1.Text=input; } label1.BackColor = Color.Red; label1.Left = panel1.Width; timer = new Timer(); timer.Interval = 10; timer.Tick += new EventHandler(timer_Tick); timer.Start(); } void timer_Tick(object sender, EventArgs e) { label1.Left -= 1; if ((label1.Left + label1.Width) < 0) { label1.Left = panel1.Width; } } } }
-
The followin code scrolls the text file contents, for a single line entry. how can i scroll the contents (in a single line) if i have more than one line in my text file ???? My main aim is to make a scrolling news application, by giving the input through a text file !!! plz help ---mist--- ------------------------------------------------------------------------------------------------------ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace WindowsApplication1 { public partial class FormMain : Form { Timer timer; public FormMain() { InitializeComponent(); this.DoubleBuffered = true; } private void FormMain_Load(object sender, EventArgs e) { Streamreader re = File.Opentext("C://test.txt"); string input=null; while((input=re.ReadLine()) !=null) { label1.Text=input; } label1.BackColor = Color.Red; label1.Left = panel1.Width; timer = new Timer(); timer.Interval = 10; timer.Tick += new EventHandler(timer_Tick); timer.Start(); } void timer_Tick(object sender, EventArgs e) { label1.Left -= 1; if ((label1.Left + label1.Width) < 0) { label1.Left = panel1.Width; } } } }
mist_psycho wrote:
while((input=re.ReadLine()) !=null) { label1.Text=input; }
this is reading all text and throwing away all but the last line. You need to read and store all lines in memory first, in the Load handler. File.ReadAllLines can be used for this. Then set your Control's Text property to whatever you want it to show; probably do this in the tick handler. FYI: You could do without the string array, keeping all text inside the Control, but that is much harder to do correctly. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in