c#.net

c# simple delegate

우유빛 2015. 9. 15. 15:26

private delegate void TextAppendDelegate(TextBox txt, string text);

public void TextAppend(TextBox txt, string text)

{

  if(txt.InvokeRequired)

    txt.Invoke(new TextAppendDelegate(TextAppend), new object[] {txt, text });

  else

  {

    if(txt.Lines.Length == 1000)

    {

      txt.SelectionStart = 0;

      txt.SelectionLength = txt.Text.IndexOf("\n", 0) + 1;

      txt.SelectedText = "";

    }

    txt.AppendText(text + "\n");

    txt.ScrollToCaret();

  }

}