Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to scroll the contents of a text file

how to scroll the contents of a text file

Scheduled Pinned Locked Moved C#
questioncsharplinqgraphicshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mist_psycho
    wrote on last edited by
    #1

    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; } } } }

    L 1 Reply Last reply
    0
    • M mist_psycho

      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; } } } }

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups