Stopping TextBox flicker during update

前端 未结 6 1183
情书的邮戳
情书的邮戳 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:39

    I found a solution looking on the internet:

        [System.Runtime.InteropServices.DllImport("user32.dll")]
    
        public static extern bool LockWindowUpdate(IntPtr hWndLock);
    
        internal void FillTB(TextBox tb, string mes) 
        {
           try
           {
              LockWindowUpdate(tb.Handle);
    
              // Do your thingies with TextBox tb
           }
           finally
           {
              LockWindowUpdate(IntPtr.Zero);
           }
        }
    

提交回复
热议问题