using FileWatcher; using System; using System.Drawing; using System.Media; using System.Threading; using System.Windows.Forms; namespace FileWatcher { public partial class RichTextAutoBottom : RichTextBox { Thread thread; string FileName = ""; public RichTextAutoBottom() { InitializeComponent(); thread = new Thread(PlaySound); TextChanged += RichTextBox_TextChange; } private void RichTextBox_TextChange(object sender, EventArgs e) { SelectionStart = Text.Length; ScrollToCaret(); } public void AppendText(string str) { base.AppendText(str); //如果颜色是红色则进行提示音 LogManager.DoLog(FindForm().Tag + str); } /// /// color设置AppendText的颜色 /// /// /// public void AppendText(string str, Color color) { SelectionColor = color; base.AppendText(str); //如果颜色是红色则进行提示音 LogManager.DoLog(FindForm().Tag + str); } /// /// 提示错误信息清楚指定控件的值 /// /// /// /// public void AppendText(string str, Color color, Control ctl) { SelectionColor = color; base.AppendText(str); ctl.Text = ""; //如果颜色是红色则进行提示音 LogManager.DoLog(FindForm().Tag + str); } private void PlaySound() { //要加载COM组件:Microsoft speech object Library if (!System.IO.File.Exists(FileName)) { return; } try { SoundPlayer player = new SoundPlayer(); player.SoundLocation = FileName; player.Load(); player.Play(); } catch (Exception e) { MessageBox.Show(e.Message); } } } }