Form1.cs
上传用户:china_pc
上传日期:2022-07-29
资源大小:495k
文件大小:4k
源码类别:

其他

开发平台:

Visual C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. using DotNetSpeech;
  10. namespace MyDictApp
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         TextReader reader; 
  19.         private void searchBtn_Click(object sender, EventArgs e)
  20.         {
  21.             //reader = new StreamReader("words.txt",Encoding.Default);
  22.             //string word = wordBox.Text;
  23.             //string temp = "";
  24.             //while ((temp = reader.ReadLine())!=null)
  25.             //{
  26.             //    if (temp.IndexOf(word)!= -1)
  27.             //    {
  28.             //        string str = word;
  29.             //        textBox2.Text = word + "rn" + reader.ReadLine();
  30.             //        return;
  31.             //    }
  32.             //    textBox2.Text = word + "没有找到";
  33.             //}
  34.             richTextBox1.Clear();
  35.             richTextBox1.AppendText(searchWord(wordBox.Text, "words.txt", "简明英汉词典"));
  36.             richTextBox1.AppendText("rn--------rn");
  37.             richTextBox1.AppendText(searchWord(wordBox.Text, "Gre.txt", "Gre"));
  38.             richTextBox1.AppendText("rn--------rn");
  39.             richTextBox1.AppendText(searchWord(wordBox.Text, "Cet4.txt", "Cet4"));
  40.             richTextBox1.AppendText("rn--------rn");
  41.         }
  42.         public string searchWord(string w,string p,string dn)
  43.         {
  44.             string word = w;
  45.             string path = p;
  46.             string temp = "";
  47.             string result = "";
  48.             string dict = dn;
  49.             StreamReader sr = new StreamReader(p, Encoding.Default);
  50.             while ((temp = sr.ReadLine()) != null)
  51.             {
  52.                 if (temp.IndexOf(word) != -1)
  53.                 {
  54.                     string str = word;
  55.                     result = "dict: " + dict + "rn" + "word: " + word + "rn" + "explain: " + sr.ReadLine();
  56.                     return result;
  57.                 }
  58.                 else
  59.                 {
  60.                     result = "dict: " + dict + "rn" + "word: " + word + "rn" + "explain: " + "found";
  61.                 }
  62.             }
  63.             return result;
  64.         }
  65.         private void Form1_Load(object sender, EventArgs e)
  66.         {
  67.             if (!File.Exists("words.txt"))
  68.             {
  69.                 MessageBox.Show("没有找到词库,请确认目录下包含"word.txt"文件!");
  70.                 return;
  71.             }
  72.         }
  73.         private void aboutBtn_Click(object sender, EventArgs e)
  74.         {
  75.             //Speak speak = new Speak();
  76.             //speak.say("good");
  77.             MessageBox.Show("C#练手之作" + "n" + "QQ:79990675" + "n" + "        By:float");
  78.         }
  79.         private void copyBtn_Click(object sender, EventArgs e)
  80.         {
  81.             richTextBox1.Copy();
  82.         }
  83.         private void sayBtn_Click(object sender, EventArgs e)
  84.         {
  85.             try
  86.             {
  87.                 DotNetSpeech.SpeechVoiceSpeakFlags SSF = DotNetSpeech.SpeechVoiceSpeakFlags.SVSFlagsAsync;
  88.                 DotNetSpeech.SpVoice vo = new SpVoiceClass();
  89.                 vo.Speak(this.wordBox.Text, SSF);
  90.             }
  91.             catch (System.Exception ec)
  92.             {
  93.                 MessageBox.Show(ec.ToString(), "SpeechApp", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
  94.             }
  95.         }
  96.         private void quitBtn_Click(object sender, EventArgs e)
  97.         {
  98.             this.Close();
  99.         }
  100.         private void outBtn_Click(object sender, EventArgs e)
  101.         {
  102.             saveFileDialog1.ShowDialog();
  103.             if (saveFileDialog1.FileName != "")
  104.             {
  105.                 richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);
  106.             }
  107.         }
  108.     }
  109. }