public void AddToCommandTrace(Command cmd) { CommandStringParser parser = new CommandStringParser(""); bool valid = parser.SplitCommand(cmd.ToString(), out string cmdTag, out string argumentPart); int offset = m_txtCommandTrace.TextLength; string cmdString = cmd.ToString() + Environment.NewLine; // dump command m_txtCommandTrace.AppendText(cmdString); if (!valid) { return; } // color command name red m_txtCommandTrace.Select(offset, offset + cmdTag.Length); m_txtCommandTrace.SelectionColor = Color.Red; // let offset point right behind the command offset += cmdTag.Length; // color argument names blue and argument values black if (!string.IsNullOrEmpty(argumentPart)) { foreach (NameValuePair nameValuePair in parser.GetNameValuePairs(argumentPart)) { m_txtCommandTrace.Select(offset + nameValuePair.NameFrom, offset + nameValuePair.NameTo); m_txtCommandTrace.SelectionColor = Color.Blue; m_txtCommandTrace.Select(offset + nameValuePair.ValueFrom, offset + nameValuePair.ValueTo); m_txtCommandTrace.SelectionColor = Color.Black; } } m_txtCommandTrace.DeselectAll(); m_txtCommandTrace.ScrollToCaret(); return; /* * int index = 0; * while (index < cmdString.Length && cmdString[index] != ' ' && cmdString[index] != ';') * { * index++; * } * this.m_txtCommandTrace.Select(offset, offset + index); * this.m_txtCommandTrace.SelectionColor = Color.Red; * * this.m_txtCommandTrace.Select(offset + index, this.m_txtCommandTrace.TextLength); * this.m_txtCommandTrace.SelectionColor = Color.Blue; * this.m_txtCommandTrace.DeselectAll(); * this.m_txtCommandTrace.ScrollToCaret();*/ }