Exemplo n.º 1
0
 // 设置固定翻译坐标
 private void button_SetPosition_Click(object sender, EventArgs e)
 {
     try
     {
         IntPtr hwnd = FindAndActiveWindow();
         using (var shot = new FrmScreenShot())
         {
             // 显示截图窗口
             if (shot.Start(hwnd) == DialogResult.Cancel)
             {
                 throw new Exception("用户取消截图!");
             }
             // 保存截图坐标高宽
             screenRect = shot.SelectedArea;
         }
         //if (screenRect.X >= 0 && screenRect.Y >= 0 && screenRect.Width > 0 && screenRect.Height > 0)
         //    MessageBox.Show("设置成功!\n请点击“保存配置”按钮。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
         //else
         //    throw new Exception("设置失败,请重试!");
         MessageBox.Show("设置成功!\n请点击“保存配置”按钮。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show("设置固定翻译坐标失败!\n原因:" + ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         MinimizeWindow(false);
     }
 }
Exemplo n.º 2
0
        // 截图翻译
        private void ScreenTranslation()
        {
            Image captureImage;

            if (st != null && !st.IsDisposed)
            {
                st.Dispose();
            }
            try
            {   // 隐藏窗口
                this.Invoke(new Action(() => MinimizeWindow(true)));
                Thread.Sleep(200);
                // 如果是固定区域翻译(isFixedScreen = true则视为固定区域翻译)
                if (isFixedScreen)
                {
                    captureImage = FixedScreen();
                }
                else
                {
                    if (shot != null && !shot.IsDisposed)
                    {
                        shot.Dispose();
                    }
                    shot = new FrmScreenShot();
                    if (shot.Start() == DialogResult.Cancel) // 显示截图窗口
                    {
                        return;
                    }
                    captureImage = (Image)shot.CaptureImage?.Clone();
                }
                TranslateAndShowResult(captureImage);
            }
            catch (Exception ex)
            {
                ShowText("错误:" + ex.Message);
            }
        }