PreviewPure.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using PaintDotNet;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace Metis.AutoAnalysis
  12. {
  13. public partial class PreviewPure : Form
  14. {
  15. private static PreviewPure _instacne;
  16. private static Button _switch;
  17. /// <summary>
  18. /// 启动预览
  19. /// </summary>
  20. /// <param name="swith">父窗口打开、关闭预览按钮</param>
  21. /// <returns></returns>
  22. public static PreviewPure StartPreiew(Button swith)
  23. {
  24. if (_instacne == null)
  25. {
  26. _instacne = new PreviewPure();
  27. swith.Click += Swith_Click;
  28. _instacne.FormClosing += (s, e) =>
  29. {
  30. swith.Click -= Swith_Click;
  31. swith.BackColor = SystemColors.Control;
  32. _instacne = null;
  33. };
  34. }
  35. _instacne.Show();
  36. _instacne.Text = PdnResources.GetString("AutoAnalysis.Preview");
  37. swith.BackColor = Color.Lime;
  38. return _instacne;
  39. }
  40. private static void Swith_Click(object sender, EventArgs e)
  41. {
  42. _instacne.Close();
  43. }
  44. public PreviewPure()
  45. {
  46. InitializeComponent();
  47. }
  48. public static void ShowPrieview(Bitmap img)
  49. {
  50. if (_instacne == null)
  51. return;
  52. try
  53. {
  54. _instacne.pictureBox1.Image = (Image)img.Clone();
  55. }
  56. catch (Exception ex)
  57. {
  58. Console.WriteLine(ex.StackTrace, ex.Message);
  59. }
  60. }
  61. public static void ShowImage(string file, string name)
  62. {
  63. try
  64. {
  65. var form = new PreviewPure();
  66. form.Text = name;
  67. form.pictureBox1.Image = new Bitmap(file);
  68. form.Show();
  69. }
  70. catch
  71. { }
  72. }
  73. }
  74. }