Ejemplo n.º 1
0
        private void BtnSearch_Click(object sender, EventArgs e)
        {
            Tbx.Clear();
            LbxWord.Items.Clear();
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.InitialDirectory = AppInfoHelper.GetArticleFolder();
            dialog.Multiselect      = false; //该值确定是否可以选择多个文件
            dialog.Title            = "请选择文件夹";
            dialog.Filter           = "所有文件(*.xml)|*.xml";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                articlePath     = dialog.FileName;
                TbxArticle.Text = dialog.SafeFileName.Replace(".xml", "");
            }
            words        = new HashSet <string>();
            dict         = CbxDictionary.Text;
            wordList     = new List <string>();
            transList    = new List <string>();
            phoneticList = new List <string>();
            if (File.Exists(articlePath))
            {
                MPB.Value = 0;
                MPB.Show();
                OpenArticle();
                t = new Thread(BackgroundProcess);
                t.IsBackground = true;
                t.Start();
            }
        }
Ejemplo n.º 2
0
 private void BtnSearch_Click(object sender, EventArgs e)
 {
     Tbx.Clear();
     if (CbxDictionary.Text == "有道词典")
     {
         try
         {
             if (GetTransOnWeb(CbxSearch.Text) == "")
             {
                 if (CbxSearch.Text != "")
                 {
                     Tbx.AppendText("不在此词典中");
                 }
             }
             else
             {
                 Tbx.AppendText(GetPhoneticOnWeb(CbxSearch.Text));
                 Tbx.AppendText(GetTransOnWeb(CbxSearch.Text));
             }
         }
         catch (System.Net.WebException webe)
         {
             Console.WriteLine("Exception caught: {0}", webe);
             Tbx.AppendText("无法连接到远程服务器,请检查网络设置!");
         }
     }
     else
     {
         if (File.Exists(dictDict[CbxDictionary.Text]))
         {
             if (GetTransFromBook(dictDict[CbxDictionary.Text], CbxSearch.Text) == "")
             {
                 if (CbxSearch.Text != "")
                 {
                     Tbx.AppendText("不在此词典中");
                 }
             }
             else
             {
                 Tbx.AppendText(GetPhoneticFromBook(dictDict[CbxDictionary.Text], CbxSearch.Text));
                 Tbx.AppendText("\r\n");
                 Tbx.AppendText(GetTransFromBook(dictDict[CbxDictionary.Text], CbxSearch.Text));
             }
         }
         else
         {
             MessageBox.Show("找不到词典,请添加词典!");
         }
     }
 }