Stopping TextBox flicker during update

前端 未结 6 1175
情书的邮戳
情书的邮戳 2020-12-20 12:26

My WinForms application has a TextBox that I\'m using as a log file. I\'m appending text without the form flickering using TextBox.AppendText(string);, however

6条回答
  •  温柔的废话
    2020-12-20 12:44

    The problem is that you are adding (removing) one character at a time repeatedly and quickly. One solution would be to buffer the characters as they are being added and update the textbox at greater intervals (regardless of the amount of characters), for example, every 250 milliseconds.

    This would require:

    • to have an array or stack of characters where they get added
    • to have a timer that would call a delegate that would actually do the update with the characters stored in the stack

    Another option is to use both every 250 ms and 100 chars, whatever happens first. But this would probably complicate the code more without any tangible benefit.

提交回复
热议问题