using System; using System.Drawing; using System.Threading; using System.Windows.Forms; using UAS_MES.PublicMethod; namespace UAS_MES.CustomControl.RichText { public partial class RichTextAutoBottom : RichTextBox { Thread thread; string FileName = Application.StartupPath + @"\Resources\Sound\Windows Background.wav"; public RichTextAutoBottom() { InitializeComponent(); 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) { thread = new Thread(PlaySound); thread.Start(); } } private void PlaySound() { //要加载COM组件:Microsoft speech object Library if (!System.IO.File.Exists(FileName)) { return; } SpeechLib.SpVoiceClass pp = new SpeechLib.SpVoiceClass(); SpeechLib.SpFileStreamClass spFs = new SpeechLib.SpFileStreamClass(); spFs.Open(FileName, SpeechLib.SpeechStreamFileMode.SSFMOpenForRead, true); SpeechLib.ISpeechBaseStream Istream = spFs as SpeechLib.ISpeechBaseStream; try { pp.SpeakStream(Istream, SpeechLib.SpeechVoiceSpeakFlags.SVSFIsFilename); } catch (Exception) { Entity.SystemInf.CheckAudioEnable = false; } spFs.Close(); } } }