123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Metis.AutoAnalysis
- {
- public partial class PreviewPure : Form
- {
- private static PreviewPure _instacne;
- private static Button _switch;
- /// <summary>
- /// 启动预览
- /// </summary>
- /// <param name="swith">父窗口打开、关闭预览按钮</param>
- /// <returns></returns>
- public static PreviewPure StartPreiew(Button swith)
- {
- if (_instacne == null)
- {
- _instacne = new PreviewPure();
- swith.Click += Swith_Click;
- _instacne.FormClosing += (s, e) =>
- {
- swith.Click -= Swith_Click;
- swith.BackColor = SystemColors.Control;
- _instacne = null;
- };
- }
- _instacne.Show();
- swith.BackColor = Color.Lime;
- return _instacne;
- }
- private static void Swith_Click(object sender, EventArgs e)
- {
- _instacne.Close();
- }
- public PreviewPure()
- {
- InitializeComponent();
- }
- public static void ShowPrieview(Bitmap img)
- {
- if (_instacne == null)
- return;
- try
- {
- _instacne.pictureBox1.Image = (Image)img.Clone();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.StackTrace, ex.Message);
- }
- }
- public static void ShowImage(string file, string name)
- {
- try
- {
- var form = new PreviewPure();
- form.Text = name;
- form.pictureBox1.Image = new Bitmap(file);
- form.Show();
- }
- catch
- { }
- }
- }
- }
|