Пример #1
0
        // 翻译
        private string Translate(bool sendToWindow)
        {
            string from = "auto", dst = "";

            try
            {
                if (textBox1_Source.Text == "")
                {
                    return("");
                }

                if (comboBox2_DestLang.SelectedItem.ToString() != "不翻译")
                {
                    if (tranInterface.IndexOf("百度") != -1)
                    {
                        Baidu.Translation(textBox1_Source.Text, from, Baidu_to[comboBox2_DestLang.SelectedIndex], out string src, out dst);
                    }
                    else if (tranInterface.IndexOf("有道") != -1)
                    {
                        dst = Youdao.Translation(textBox1_Source.Text, from, Youdao_to[comboBox2_DestLang.SelectedIndex]);
                    }
                    else if (tranInterface.IndexOf("腾讯") != -1)
                    {
                        dst = Tengxun.Translation(textBox1_Source.Text, from, Tengxun_to[comboBox2_DestLang.SelectedIndex]);
                    }
                }
                else
                {
                    dst = textBox1_Source.Text;
                }

                // 保存当前选项
                FrmMain.TranDestLang = comboBox2_DestLang.SelectedIndex;
                FrmMain.AutoPressKey = comboBox1_SourceLang.SelectedIndex;
                FrmMain.AutoSend     = checkBox1_AutoSend.Checked;

                if (!sendToWindow) // 不将译文发送到窗口
                {
                    return(dst);
                }
                else
                {
                    this.WindowState = FormWindowState.Minimized;
                    SendText(dst);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "翻译", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (sendToWindow) // 如果是不将译文发送到窗口,则不会关闭本窗口
                {
                    this.Close();
                }
            }

            return(dst);
        }
Пример #2
0
        private void YoudaoTranslation()
        {
            chkYoudao.Checked = false;
            chkYoudao.Enabled = false;

            textYoudao.Text = Youdao.Translation(textOriginal.Text, langDic["必应"][cobForm.Text], langDic["必应"][cobTo.Text]);

            chkYoudao.Enabled = true;
            chkYoudao.Checked = true;
        }