Application, have a TextBlock and two Buttons, the text is displayed TextBlock by clicking on the button (the text of the Q.txt is read line by line, over a hundred lines):
public class QWork
{
public static int counter = 0;
public static string GetQ()
{
var qFile = new List<string>();
string pathFile = "Q.txt";
Uri uri = new Uri(pathFile, UriKind.Relative);
StreamResourceInfo sri = Application.GetResourceStream(uri);
using (StreamReader sr = new StreamReader(sri.Stream))
{
string line = "";
while (line != null)
{
line = sr.ReadLine();
if (line != null)
qFile.Add(line); // Add to list
}
return qFile[counter];
}
}
}
Buttons event handler:
private void RightButton_Click(object sender, RoutedEventArgs e)//Next text
{
qTextBlock.Text = QWork.GetQ();
QWork.counter++;
}
private void LeftButton_Click(object sender, RoutedEventArgs e)//Previous text
{
qTextBlock.Text = QWork.GetQ();
QWork.counter --;
}
Problem:
When I click LeftButton, a first still shows the following line, but only after previous.
Tell me please, how can I fix it.
Thanks!
Maybe this can help you