PatchPrgDialog.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using MeterVision.Patch;
  2. using System;
  3. using System.Windows;
  4. //using MeterVision.Controls; // 引入 UserControl 所在的命名空间
  5. namespace MeterVision.Dlg
  6. {
  7. public partial class PatchPrgDialog : Window
  8. {
  9. //public event EventHandler<StopProcessEventArgs> OnStopProcess;
  10. private UCPatchGrid imageProcessingControl; // 引用主窗体中的 UserControl
  11. private bool isProcessing = false;
  12. // 构造函数,接收 UserControl 以便启动/停止处理
  13. public PatchPrgDialog(UCPatchGrid control)
  14. {
  15. InitializeComponent();
  16. imageProcessingControl = control;
  17. // 订阅 UserControl 中的事件
  18. //imageProcessingControl.OnProcessingProgressChanged += ImageProcessingControl_OnProcessingProgressChanged;
  19. //imageProcessingControl.OnProcessingCompleted += ImageProcessingControl_OnProcessingCompleted;
  20. //imageProcessingControl.OnProcessingStopped += ImageProcessingControl_OnProcessingStopped;
  21. }
  22. // 显示对话框并启动处理
  23. public void StartProcessing()
  24. {
  25. progressText.Text = "开始处理...";
  26. progressBar.Value = 0;
  27. progressBar.Maximum = 100;
  28. stopButton.IsEnabled = true;
  29. isProcessing = true;
  30. Owner = Application.Current.MainWindow;
  31. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  32. //this.ShowDialog(); // 显示对话框
  33. this.Show();
  34. //imageProcessingControl.StartProcessing(); // 启动图片处理
  35. }
  36. // 更新进度条和进度文本
  37. private void ImageProcessingControl_OnProcessingProgressChanged(int currentImage, int totalImages)
  38. {
  39. double progress = (double)currentImage / totalImages * 100;
  40. progressBar.Value = progress;
  41. progressText.Text = $"正在处理:{currentImage}/{totalImages}";
  42. }
  43. // 处理完成后的事件
  44. private void ImageProcessingControl_OnProcessingCompleted()
  45. {
  46. progressText.Text = "处理完成!";
  47. stopButton.IsEnabled = false; // 禁用停止按钮
  48. isProcessing = false;
  49. this.Close(); // 关闭对话框
  50. }
  51. // 处理停止后的事件
  52. private void ImageProcessingControl_OnProcessingStopped()
  53. {
  54. progressText.Text = "处理已停止。";
  55. stopButton.IsEnabled = false; // 禁用停止按钮
  56. isProcessing = false;
  57. this.Close(); // 关闭对话框
  58. }
  59. // 点击停止按钮时,停止处理
  60. private void StopButton_Click(object sender, RoutedEventArgs e)
  61. {
  62. if (isProcessing)
  63. {
  64. //imageProcessingControl.StopProcessing(); // 停止处理
  65. }
  66. }
  67. //public void UpdateProgress(int currentNum,int totalNum)
  68. //{
  69. // Dispatcher.Invoke(() =>
  70. // {
  71. // double progress = (double)currentNum / totalNum * 100;
  72. // progressBar.Value = progress;
  73. // progressText.Text = $"正在处理:{currentNum}/{totalNum}";
  74. // });
  75. //}
  76. // 处理完成后的事件
  77. // 点击停止按钮时,停止处理
  78. //private void StopButton_Click(object sender, RoutedEventArgs e)
  79. //{
  80. // stopButton.IsEnabled = false; //防止连续点击
  81. // OnStopProcess?.Invoke(this, new StopProcessEventArgs());
  82. //}
  83. }
  84. //按下停止按钮的事件
  85. public class StopProcessEventArgs : EventArgs
  86. {
  87. public StopProcessEventArgs()
  88. {
  89. }
  90. }
  91. //----------------------------------------------------------------------
  92. }