How to show one string of row at a time in a textbox

  • Thread starter Thread starter MorenainHanoi
  • Start date Start date
M

MorenainHanoi

Guest
So, this is what i've done so far, but it shows the whole file at once instead of showing one string row at time.

I have only one textbox which must like a book list like this "Origins" by Dan Brown. (Novel) with each click.

My imported file has a long list of books but this program shows a whole list in one single line instead.

I'm thinking of using random to get a random list, but i have difficulty figuring it out.



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

namespace WindowsFormsApp1
{
public partial class FileLoader : Form
{
List<string> itemSaver = new List<string>();

public FileLoader()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
this.button1.Text = "Browse!";
var sb = new StringBuilder();
string item;

if (File.Exists("texter.txt"))
{
StreamReader reader = new StreamReader("texter.txt", Encoding.Default, false);


while ((item = reader.ReadLine()) != null)
{
itemSaver.Add(item);
}
}

foreach (string a in itemSaver)
{
string[] vektor = a.Split(new string[] { "###" }, StringSplitOptions.None);

sb.AppendLine(string.Format("\"{0}\" by {1}. ({2})", vektor));
}
this.textBox1.AppendText(sb.ToString());


}
}
}

Continue reading...
 
Back
Top