ToastWindow.xaml.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using ivf_tl_Manage.Converts;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Timers;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace ivf_tl_Manage.Win
  17. {
  18. /// <summary>
  19. /// SuccessToastWindow.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class ToastWindow : Window
  22. {
  23. private Window parent = null;
  24. public System.Timers.Timer timer;
  25. public ToastWindow(Window w, double viewWidth, double top, bool b)
  26. {
  27. InitializeComponent();
  28. if (!b)
  29. {
  30. SetImage();
  31. this.image1.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DefeatToastIcon2.png", UriKind.Absolute));
  32. this.textString.Text = KeyToStringConvert.GetLanguageStringByKey("0286");
  33. }
  34. timer = new System.Timers.Timer(1500);
  35. timer.Enabled = false;
  36. timer.AutoReset = false;
  37. timer.Elapsed += timer_Elapsed;
  38. this.Owner = w;
  39. this.parent = w;
  40. //this.Top = top;
  41. //this.Left = (viewWidth / 2) - 75;
  42. Loaded += (a, b) =>
  43. {
  44. this.Top = top;
  45. this.Left = (viewWidth / 2) - (this.ActualWidth / 2);
  46. };
  47. this.Closed += (a, b) =>
  48. {
  49. if (parent != null)
  50. {
  51. parent.Activate();
  52. }
  53. };
  54. timer.Start();
  55. }
  56. public ToastWindow(Window w, double viewWidth, double top, bool b, string string1)
  57. {
  58. InitializeComponent();
  59. if (!b)
  60. {
  61. SetImage();
  62. this.image1.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DefeatToastIcon2.png", UriKind.Absolute));
  63. this.textString.Text = string1;
  64. }
  65. timer = new System.Timers.Timer(1500);
  66. timer.Enabled = false;
  67. timer.AutoReset = false;
  68. timer.Elapsed += timer_Elapsed;
  69. this.Owner = w;
  70. this.parent = w;
  71. Loaded += (a, b) =>
  72. {
  73. this.Top = top;
  74. this.Left = (viewWidth / 2) - (this.ActualWidth / 2);
  75. };
  76. this.Closed += (a, b) =>
  77. {
  78. if (parent != null)
  79. {
  80. parent.Activate();
  81. }
  82. };
  83. timer.Start();
  84. }
  85. public ToastWindow(Window w, bool b)
  86. {
  87. InitializeComponent();
  88. if (!b) SetImage();
  89. timer = new System.Timers.Timer(1500);
  90. timer.Enabled = false;
  91. timer.AutoReset = false;
  92. timer.Elapsed += timer_Elapsed;
  93. this.Owner = w;
  94. this.parent = w;
  95. this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  96. this.Closed += (a, b) =>
  97. {
  98. if (parent != null)
  99. {
  100. parent.Activate();
  101. }
  102. };
  103. timer.Start();
  104. }
  105. private void timer_Elapsed(object? sender, ElapsedEventArgs e)
  106. {
  107. timer.Stop();
  108. timer.Enabled = false;
  109. timer.Close();
  110. timer.Dispose();
  111. Dispatcher.Invoke(() =>
  112. {
  113. this.Close();
  114. });
  115. }
  116. private void SuccessShow(Window parent, double viewWidth)
  117. {
  118. timer.Start();
  119. this.Owner = parent;
  120. this.parent = parent;
  121. this.Top = 0;
  122. this.Left = (viewWidth / 2) - 75;
  123. this.Show();
  124. }
  125. private void DefeatShow(Window parent, double viewWidth)
  126. {
  127. timer.Start();
  128. this.Owner = parent;
  129. this.parent = parent;
  130. SetImage();
  131. this.Top = 0;
  132. this.Left = (viewWidth / 2) - 75;
  133. this.Show();
  134. }
  135. private void SetImage()
  136. {
  137. //this.image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DefeatToastIcon1.png", UriKind.Absolute));
  138. //this.image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DefeatToastIcon.png", UriKind.Absolute));
  139. //this.image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DefeatToastIcon3.png", UriKind.Absolute));
  140. //this.image.Width = 255;
  141. //this.image.Height = 84;
  142. //this.image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DefeatToastIcon.png", UriKind.Absolute));
  143. this.rootGrid.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DefeatToastIcon1.png", UriKind.Absolute)));
  144. }
  145. }
  146. }