| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 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 = "";
- public RichTextAutoBottom()
- {
- InitializeComponent();
- thread = new Thread(PlaySound);
- TextChanged += RichTextBox_TextChange;
- }
- private void RichTextBox_TextChange(object sender, EventArgs e)
- {
- SelectionStart = Text.Length;
- ScrollToCaret();
- }
- /// <summary>
- /// color设置AppendText的颜色
- /// </summary>
- /// <param name="str"></param>
- /// <param name="color"></param>
- public void AppendText(string str, Color color)
- {
- SelectionColor = color;
- base.AppendText(str);
- //如果颜色是红色则进行提示音
- if (color == Color.Red && Entity.SystemInf.CheckAudioEnable)
- {
- FileName = Application.StartupPath + @"\Resources\Sound\5185.wav";
- }
- else if(color == Color.Green && Entity.SystemInf.CheckAudioEnable)
- {
- //颜色是绿色,进行正确提示音
- FileName = Application.StartupPath + @"\Resources\Sound\8378.wav";
- }
- thread.Start();
- thread = new Thread(PlaySound);
- }
- /// <summary>
- /// 提示错误信息清楚指定控件的值
- /// </summary>
- /// <param name="str"></param>
- /// <param name="color"></param>
- /// <param name="ctl"></param>
- 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\5185.wav";
- }
- else if(color == Color.Green && Entity.SystemInf.CheckAudioEnable)
- {
- //颜色是绿色,进行正确提示音
- FileName = Application.StartupPath + @"\Resources\Sound\8378.wav";
- }
- thread.Start();
- thread = new Thread(PlaySound);
- }
- private void PlaySound()
- {
- //要加载COM组件:Microsoft speech object Library
- if (!System.IO.File.Exists(FileName))
- {
- return;
- }
- try
- {
- 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;
- pp.SpeakStream(Istream, SpeechLib.SpeechVoiceSpeakFlags.SVSFIsFilename);
- spFs.Close();
- }
- catch (Exception)
- {
- Entity.SystemInf.CheckAudioEnable = false;
- }
- }
- }
- }
|