Exemplo n.º 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);
        }
Exemplo n.º 2
0
        //private DialogResult ShowScreenShotDialog(out Image img)
        //{
        //    if (shot != null && !shot.IsDisposed)
        //        shot.Dispose();

        //    shot = new FrmScreenShot();
        //    if (shot.Start() == DialogResult.Cancel) // 显示截图窗口
        //    {
        //        img = null;
        //        return DialogResult.Cancel;
        //    }
        //    else
        //    {
        //        img = (Image)shot.CaptureImage?.Clone();
        //        return DialogResult.OK;
        //    }
        //}

        // 调用翻译Api翻译后显示翻译结果
        private async void TranslateAndShowResult(Image captureImage)
        {
            string src = "", dst = "";
            await Task.Run(() =>
            {
                try
                {
                    if (tranInterface.IndexOf("百度") != -1)
                    {
                        Baidu.PictureTranslation(captureImage, "auto", Baidu.LangDict[destLang], out src, out dst);
                    }
                    else if (tranInterface.IndexOf("有道") != -1)
                    {
                        Youdao.PictureTranslation(captureImage, "auto", Youdao.LangDict[destLang], out src, out dst);
                    }
                    else if (tranInterface.IndexOf("腾讯") != -1)
                    {
                        Tengxun.PictureTranslation(captureImage, "auto", Tengxun.LangDict[destLang], out src, out dst);
                    }
                }
                catch (Exception ex)
                {
                    dst = ("错误:" + ex.Message);
                }
            });

            if (copySourceTextToClip)
            {
                Clipboard.SetText(src);// 复制原文到剪切板
            }
            if (copyDestTextToClip)
            {
                Clipboard.SetText(dst);// 复制译文到剪切板
            }
            if (isSpeak)
            {
                Speech(dst);                              // 文字转语音
            }
            this.Invoke(new Action(() => ShowText(dst))); // 显示到桌面
        }
Exemplo n.º 3
0
 private void button_TengXunKeyTest_Click(object sender, EventArgs e)
 {
     if (TextBoxIsEmpty(groupBox3))// 先判断是否有 没有填的项
     {
         return;
     }
     TextBoxRemoveSpace(groupBox3); // 移除空格
     SaveTengXunKeyToDict();        // 先保存数据
     if (!Tengxun.TengxunKeyTest()) // 有道翻译
     {
         return;
     }
     try
     {
         ConfigFile.WriteFile(config);
         MessageBox.Show("测试成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show("保存到文件失败!\n" + ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }