RichTextBox Log
/// <summary> Log data to the terminal window. </summary>
/// <param name="msgtype"> The type of message to be written. </param>
/// <param name="msg"> The string containing the message to be shown. </param>
private void Log(LogMsgType msgtype, string msg, RichTextBox sRichTextBox)
{
rtfTerminal.Invoke(new EventHandler(delegate
{
sRichTextBox.SelectedText = string.Empty;
sRichTextBox.SelectionFont = new Font(rtfTerminal.SelectionFont, FontStyle.Bold);
sRichTextBox.SelectionColor = LogMsgTypeColor[(int)msgtype];
sRichTextBox.AppendText(msg);
sRichTextBox.ScrollToCaret();
}));
}
public enum LogMsgType { Incoming, Outgoing, Normal, Warning, Error };
Log(LogMsgType.Error, String.Format(ex.Message.ToString() + "at {0}\n", DateTime.Now), rtfError);
Log(LogMsgType.Normal, String.Format("Application Started at {0}\n", DateTime.Now), rtfTerminal);
留言
張貼留言