示例#1
0
        public void updateTextBox(string msg)
        {
            // 有調用需求
            if (this.InvokeRequired)
            {
                // 建立Dalegate 物件

                /*
                 * 建立委派物件(TextBoxDalegate)並委派使用"updateTextBox"方法
                 */
                TextBoxDalegate TBDalegate = new TextBoxDalegate(updateTextBox);

                // 調用委派的方法
                this.Invoke(TBDalegate, msg);
            }
            else
            {
                int lineCount = ConsoleTextBox.GetLineFromCharIndex(ConsoleTextBox.Text.Length);

                if (lineCount >= 100)
                {
                    ConsoleTextBox.Text = ConsoleTextBox.Text.Remove(0, (ConsoleTextBox.Lines[0].Length + Environment.NewLine.Length));
                }

                ConsoleTextBox.Text          += msg;
                ConsoleTextBox.Text          += Environment.NewLine;
                ConsoleTextBox.SelectionStart = ConsoleTextBox.Text.Length;
                ConsoleTextBox.ScrollToCaret();
            }
        }