using System; using System.Drawing; using System.Media; using System.Threading; using System.Windows.Forms; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.CustomControl.RichText { 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(); } /// /// color设置AppendText的颜色 /// /// /// public void AppendText(string str, Color color) { SelectionColor = color; base.AppendText(str); //如果颜色是红色则进行提示音 if (color == Color.Red && Entity.SystemInf.CheckAudioEnable) { FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\4082.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\失败.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\打印.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\批过.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\批退.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav"; thread.Start(); thread = new Thread(PlaySound); } LogManager.DoLog(FindForm().Tag + str); } /// /// 提示错误信息清楚指定控件的值 /// /// /// /// public void AppendText(string str, Color color, Control ctl) { SelectionColor = color; base.AppendText(str); ctl.Text = ""; //如果颜色是红色则进行提示音 if (color == Color.Red && Entity.SystemInf.CheckAudioEnable) { FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\4082.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\失败.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\打印.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\批过.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\批退.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav"; thread.Start(); thread = new Thread(PlaySound); } LogManager.DoLog(FindForm().Tag + str); } /// /// 提示错误信息清楚指定控件的值 /// /// /// /// public void AppendText(string str, Color color, Control ctl, Control ct2) { SelectionColor = color; base.AppendText(str); ctl.Text = ""; ct2.Text = ""; //如果颜色是红色则进行提示音 if (color == Color.Red && Entity.SystemInf.CheckAudioEnable) { FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\4082.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\失败.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\打印.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\批过.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\批退.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav"; thread.Start(); thread = new Thread(PlaySound); } LogManager.DoLog(FindForm().Tag + str); } /// /// 提示错误信息清楚指定控件的值 /// /// /// /// public void AppendText(string str, Color color, Control ctl, Control ct2, Control ct3) { SelectionColor = color; base.AppendText(str); ctl.Text = ""; ct2.Text = ""; ct3.Text = ""; //如果颜色是红色则进行提示音 if (color == Color.Red && Entity.SystemInf.CheckAudioEnable) { FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\4082.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\失败.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\打印.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\批过.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\批退.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav"; thread.Start(); thread = new Thread(PlaySound); } else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable) { //颜色是绿色,进行正确提示音 FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav"; thread.Start(); thread = new Thread(PlaySound); } 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); Entity.SystemInf.CheckAudioEnable = false; } } } }