private void Button5_Click(object sender, EventArgs e) { switch (state) { case 0: case 3: if (GData.Config.User == null) { MessageBox.Show (GData.Data["Dim:System.Caption", "Caption_NonUser", "请先登录!输入用户信息后保存设置!"] , GData.Data["Dim:System.Other", "Message", "消息"]); Button4_Click(button4, new EventArgs()); return; } OutputConfig oc = null; if (GData.Config.OutType == 0) { Form_Output fo = new Form_Output(false); if (fo.ShowDialog() != DialogResult.OK) { return; } oc = fo.Value; } if (oc == null) { oc = new OutputConfig( GData.Config.OutType, GData.Config.BackupSaveType, GData.Config.BackupSavePath, GData.Config.OutputPath ); } state = 1; if (data != null) { data.Pause = false; } button5.Text = GData.Data["Dim:System.Button", "Pause", "暂停(&P)"]; GData.Baidu.SourceLanguage = (Language)Enum.Parse(typeof(Language), comboBox1.SelectedItem.ToString()); GData.Baidu.TargetLanguage = (Language)Enum.Parse(typeof(Language), comboBox2.SelectedItem.ToString()); Start(oc); break; case 1: Pause(); break; case 2: if (data != null) { data.Pause = false; } state = 1; button5.Text = GData.Data["Dim:System.Button", "Pause", "暂停(&P)"]; break; default: break; } }
private void Button2_Click(object sender, EventArgs e) { Value = null; Close(); }
private void Start(OutputConfig oc) { if (listBox1.Items.Count > 0) { string[] task = new string[listBox1.Items.Count]; listBox1.Items.CopyTo(task, 0); int current = -1; data = new VSXMLData(); data.ProgressChange += VSXMLData_ProgressChange; data.Canceled += (sender, e) => { this.Invoke(new Action(() => { label1.Text = GData.Data["Dim:System.Caption", "Message_Main_Completed", "已完成"]; textBox1.Text = GData.Data["Dim:System.Caption", "Message_Main_Completed", "已完成"]; //progressBar1.Maximum = 1; progressBar1.Value = progressBar1.Maximum; progressBar2.Maximum = 1; progressBar2.Value = 1; button5.Enabled = true; state = 3; if (data != null) { data.Pause = false; } button5.Text = GData.Data["Dim:System.Button", "Start", "开始(&S)"]; })); }; VSXMLData_ProgressChange(data, (true, 1, 1, "")); void VSXMLData_ProgressChange(VSXMLData sender, (bool IsCompleted, int Progress, int MaxValue, string Member) e) { if (e.Progress > e.MaxValue) { e.Progress = e.MaxValue; } if (e.IsCompleted) { current++; if (current == task.Length) { this.Invoke(new Action(() => { label1.Text = GData.Data["Dim:System.Caption", "Message_Main_Completed", "已完成"]; textBox1.Text = GData.Data["Dim:System.Caption", "Message_Main_Completed", "已完成"]; //progressBar1.Maximum = 1; progressBar1.Value = progressBar1.Maximum; progressBar2.Maximum = 1; progressBar2.Value = 1; button5.Enabled = true; state = 3; if (data != null) { data.Pause = false; } button5.Text = GData.Data["Dim:System.Button", "Start", "开始(&S)"]; })); return; } data.Load(task[current]); data.CreateTranslationProgress(); data.StartTranslation(oc); this.Invoke(new Action(() => { //progressBar1.Maximum = task.Length; double value = ((double)current / (double)task.Length) + ((double)progressBar2.Value / (double)progressBar2.Maximum) / (double)task.Length; progressBar1.Value = (int)Math.Floor(value * progressBar1.Maximum); label1.Text = $"{GData.Data["Dim:System.Caption", "Message_Main_CurrentTranslation", "正在翻译:"]}({progressBar1.Value}/{progressBar1.Maximum}) {task[current]}"; })); } else { this.Invoke(new Action(() => { progressBar2.Maximum = e.MaxValue; progressBar2.Value = e.Progress; textBox1.Text = $"{GData.Data["Dim:System.Caption", "Message_Main_CurrentTranslation", "正在翻译:"]}({progressBar2.Value}/{progressBar2.Maximum}) {e.Member}"; //progressBar1.Maximum = task.Length; double value = ((double)current / (double)task.Length) + ((double)progressBar2.Value / (double)progressBar2.Maximum) / (double)task.Length; progressBar1.Value = (int)Math.Floor(value * progressBar1.Maximum); label1.Text = $"{GData.Data["Dim:System.Caption", "Message_Main_CurrentTranslation", "正在翻译:"]}({current}/{task.Length}) {task[current]}"; })); } } } else { button5.Enabled = true; } }