using System; using System.Collections.Generic; using System.Linq; using System.Text; using DrawGraph; using System.Windows.Forms; namespace DrawGraph { public class TipBox : EventObj { private volatile static TipBox _instance = null; private static readonly object lockHelper = new object(); private TipBox() { } public static TipBox CreateInstance(string _type) { if (_instance == null) { lock (lockHelper) { if (_instance == null) { _instance = new TipBox(); text.IsVisible = true; isViewText = false; text.Location.X = x; text.Location.Y = y; text.Text = viewStr; text.Tag = "ZgcTip" + type; text.FontSpec = new FontSpec("宋体", 5f, System.Drawing.Color.Black, false, false, false); timer = new Timer(); timer.Interval = 800; timer.Tick += new EventHandler(timer_Tick); type = _type; } } } return _instance; } private static Timer timer; static TextObj text = new TextObj(); static bool isViewText = false; static string viewStr = ""; static string type = "sync"; static bool isMove = false; /// /// 要显示的内容 /// public string ViewStr { get { return viewStr; } set { viewStr = value; } } static double x = 0, y = 0; static double oldX = 0, oldY = 0; public void Show(double _x, double _y, bool _isMove = false) { if (zgcAnas == null) { //MessageBox.Show("未传递窗体或传递的不是麻醉单窗体"); return; } try { isMove = _isMove; text.IsVisible = isViewText; x = _x; y = _y; text.Location.X = x; text.Location.Y = y; if (zgcAnas.MasterPane == null) return; TextObj text1 = (TextObj)zgcAnas.MasterPane.GraphObjList["ZgcTip" + type]; if (text1 == null) { ZUtil.DrawText(TipBox.viewStr, TipBox.x, TipBox.y, zgcAnas, 5f, "ZgcTip" + type, true, ZOrder.A_InFront); isViewText = true; } else { isViewText = true; text = text1; text.Location.X = x; text.Location.Y = y; text.IsVisible = isViewText; text.Text = viewStr; } if (isViewText && type != "sync") { if (!timer.Enabled) { timer.Start(); } } } catch (Exception) { } } public static void Hidden(bool isShow = false) { //因为移动中所以不隐藏 if (isMove && isShow == false) return; text.IsVisible = false; if (type != "sync") { timer.Stop(); } if (TipBox._instance.zgcAnas != null) { TipBox._instance.zgcAnas.AxisChange(); TipBox._instance.zgcAnas.Refresh(); } if (isShow == true) { TextObj text1 = (TextObj)TipBox._instance.zgcAnas.MasterPane.GraphObjList["ZgcTip" + type]; if (text != null) TipBox._instance.zgcAnas.MasterPane.GraphObjList.Remove(text1); TipBox._instance.zgcAnas.Refresh(); } } protected static void timer_Tick(object sender, EventArgs e) { if ((x == TipBox.oldX) && (y == TipBox.oldY) && isViewText) { TipBox.Hidden(); } if (x != TipBox.oldX || y != TipBox.oldY) { TipBox.oldX = TipBox.x; TipBox.oldY = TipBox.y; } } } }