79150801

Date: 2024-11-02 13:50:58
Score: 1.5
Natty:
Report link

I thank you for the suggestions. Thanks to them I found a solution that solves the problem, even if the user types very fast.

private void ReadManageAndWriteLine()
{
    // open file with StreamReader
    // for every line in the file, read it and do what you need to do
    // then save the result in String outpuLine
    int cp = GetCaretPosition();
    txtBox.AppendText(outputLine + new string[] { Environment.NewLine });
    SetCaretPosition(cp);
    // go to the next line
}

private int GetCaretPosition()
{
    int s = txtBox.SelectionStart;
    return s;
}

private void SetCaretPosition(int cp)
{
    txtBox.Select(cp, 0);
    txtBox.Focus();
    txtBox.ScrollToCaret();
}

Again, thank you so much, problem solved.

Reasons:
  • Blacklisted phrase (0.5): thank you
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Stefano A.