Form1.cs
资源名称:MyDictApp.rar [点击查看]
上传用户:china_pc
上传日期:2022-07-29
资源大小:495k
文件大小:4k
源码类别:
其他
开发平台:
Visual C++
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using DotNetSpeech;
- namespace MyDictApp
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- TextReader reader;
- private void searchBtn_Click(object sender, EventArgs e)
- {
- //reader = new StreamReader("words.txt",Encoding.Default);
- //string word = wordBox.Text;
- //string temp = "";
- //while ((temp = reader.ReadLine())!=null)
- //{
- // if (temp.IndexOf(word)!= -1)
- // {
- // string str = word;
- // textBox2.Text = word + "rn" + reader.ReadLine();
- // return;
- // }
- // textBox2.Text = word + "没有找到";
- //}
- richTextBox1.Clear();
- richTextBox1.AppendText(searchWord(wordBox.Text, "words.txt", "简明英汉词典"));
- richTextBox1.AppendText("rn--------rn");
- richTextBox1.AppendText(searchWord(wordBox.Text, "Gre.txt", "Gre"));
- richTextBox1.AppendText("rn--------rn");
- richTextBox1.AppendText(searchWord(wordBox.Text, "Cet4.txt", "Cet4"));
- richTextBox1.AppendText("rn--------rn");
- }
- public string searchWord(string w,string p,string dn)
- {
- string word = w;
- string path = p;
- string temp = "";
- string result = "";
- string dict = dn;
- StreamReader sr = new StreamReader(p, Encoding.Default);
- while ((temp = sr.ReadLine()) != null)
- {
- if (temp.IndexOf(word) != -1)
- {
- string str = word;
- result = "dict: " + dict + "rn" + "word: " + word + "rn" + "explain: " + sr.ReadLine();
- return result;
- }
- else
- {
- result = "dict: " + dict + "rn" + "word: " + word + "rn" + "explain: " + "found";
- }
- }
- return result;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- if (!File.Exists("words.txt"))
- {
- MessageBox.Show("没有找到词库,请确认目录下包含"word.txt"文件!");
- return;
- }
- }
- private void aboutBtn_Click(object sender, EventArgs e)
- {
- //Speak speak = new Speak();
- //speak.say("good");
- MessageBox.Show("C#练手之作" + "n" + "QQ:79990675" + "n" + " By:float");
- }
- private void copyBtn_Click(object sender, EventArgs e)
- {
- richTextBox1.Copy();
- }
- private void sayBtn_Click(object sender, EventArgs e)
- {
- try
- {
- DotNetSpeech.SpeechVoiceSpeakFlags SSF = DotNetSpeech.SpeechVoiceSpeakFlags.SVSFlagsAsync;
- DotNetSpeech.SpVoice vo = new SpVoiceClass();
- vo.Speak(this.wordBox.Text, SSF);
- }
- catch (System.Exception ec)
- {
- MessageBox.Show(ec.ToString(), "SpeechApp", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
- }
- }
- private void quitBtn_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void outBtn_Click(object sender, EventArgs e)
- {
- saveFileDialog1.ShowDialog();
- if (saveFileDialog1.FileName != "")
- {
- richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);
- }
- }
- }
- }