/// <summary> /// Shows the tips. /// </summary> /// <param name="rectControl">The rect control.</param> /// <param name="strMsg">The string MSG.</param> /// <param name="location">The location.</param> /// <param name="background">The background.</param> /// <param name="foreColor">Color of the fore.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="autoCloseTime">The automatic close time.</param> /// <param name="parentForm">父窗体</param> /// <param name="blnTopMost">是否置顶</param> /// <returns>FrmAnchorTips.</returns> public static FrmAnchorTips ShowTips( Rectangle rectControl, string strMsg, AnchorTipsLocation location = AnchorTipsLocation.RIGHT, Color?background = null, Color?foreColor = null, int fontSize = 10, int autoCloseTime = 5000, Control parentControl = null, bool blnTopMost = true) { FrmAnchorTips frm = new FrmAnchorTips(rectControl, strMsg, location, background, foreColor, fontSize, autoCloseTime); frm.TopMost = blnTopMost; frm.Show(parentControl); //if (parentControl != null) //{ // parentControl.VisibleChanged += (a, b) => // { // try // { // Control c = a as Control; // if (CheckControlClose(c)) // { // frm.Close(); // } // } // catch (Exception ex) // { // } // }; //} return(frm); }
/// <summary> /// Initializes a new instance of the <see cref="FrmAnchorTips"/> class. /// </summary> /// <param name="rectControl">The rect control.</param> /// <param name="strMsg">The string MSG.</param> /// <param name="location">The location.</param> /// <param name="background">The background.</param> /// <param name="foreColor">Color of the fore.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="autoCloseTime">The automatic close time.</param> private FrmAnchorTips( Rectangle rectControl, string strMsg, AnchorTipsLocation location = AnchorTipsLocation.RIGHT, Color?background = null, Color?foreColor = null, int fontSize = 10, int autoCloseTime = 5000) { InitializeComponent(); m_rectControl = rectControl; m_location = location; m_background = background; m_foreColor = foreColor; m_fontSize = fontSize; StrMsg = strMsg; if (autoCloseTime > 0) { Timer t = new Timer(); t.Interval = autoCloseTime; t.Tick += (a, b) => { this.Close(); }; t.Enabled = true; } }
/// <summary> /// Shows the tips. /// </summary> /// <param name="anchorControl">The parent control.</param> /// <param name="strMsg">The string MSG.</param> /// <param name="location">The location.</param> /// <param name="background">The background.</param> /// <param name="foreColor">Color of the fore.</param> /// <param name="deviation">The deviation.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="autoCloseTime">The automatic close time.</param> /// <param name="blnTopMost">是否置顶</param> /// <returns>FrmAnchorTips.</returns> public static FrmAnchorTips ShowTips( Control anchorControl, string strMsg, AnchorTipsLocation location = AnchorTipsLocation.RIGHT, Color?background = null, Color?foreColor = null, Size?deviation = null, int fontSize = 10, int autoCloseTime = 5000, bool blnTopMost = true) { Point p; if (anchorControl is Form) { p = anchorControl.Location; } else { p = anchorControl.Parent.PointToScreen(anchorControl.Location); } if (deviation != null) { p = p + deviation.Value; } return(ShowTips(new Rectangle(p, anchorControl.Size), strMsg, location, background, foreColor, fontSize, autoCloseTime, anchorControl.Parent, blnTopMost)); }
/// <summary> /// 功能描述:显示一个提示 English:Show a hint /// 作 者:HZH /// 创建日期:2019-08-29 15:28:58 /// 任务编号: /// </summary> /// <param name="parentControl">停靠控件</param> /// <param name="strMsg">消息</param> /// <param name="location">显示方位</param> /// <param name="background">背景色</param> /// <param name="foreColor">文字颜色</param> /// <param name="deviation">偏移量</param> /// <param name="fontSize">文字大小</param> /// <param name="autoCloseTime">自动关闭时间,当<=0时不自动关闭</param> public static FrmAnchorTips ShowTips( Control parentControl, string strMsg, AnchorTipsLocation location = AnchorTipsLocation.RIGHT, Color?background = null, Color?foreColor = null, Size?deviation = null, int fontSize = 10, int autoCloseTime = 5000) { Point p; if (parentControl is Form) { p = parentControl.Location; } else { p = parentControl.Parent.PointToScreen(parentControl.Location); } if (deviation != null) { p = p + deviation.Value; } return(ShowTips(parentControl.FindForm(), new Rectangle(p, parentControl.Size), strMsg, location, background, foreColor, fontSize, autoCloseTime)); }
/// <summary> /// 功能描述:显示一个提示 English:Show a hint /// 作 者:HZH /// 创建日期:2019-08-29 15:29:07 /// 任务编号: /// </summary> /// <param name="rectControl">停靠区域</param> /// <param name="strMsg">消息</param> /// <param name="location">显示方位</param> /// <param name="background">背景色</param> /// <param name="foreColor">文字颜色</param> /// <param name="fontSize">文字大小</param> /// <param name="autoCloseTime">自动关闭时间,当<=0时不自动关闭</param> /// <returns>返回值</returns> public static FrmAnchorTips ShowTips( Rectangle rectControl, string strMsg, AnchorTipsLocation location = AnchorTipsLocation.RIGHT, Color?background = null, Color?foreColor = null, int fontSize = 10, int autoCloseTime = 5000) { FrmAnchorTips frm = new FrmAnchorTips(rectControl, strMsg, location, background, foreColor, fontSize, autoCloseTime); frm.TopMost = true; frm.Show(); return(frm); }
/// <summary> /// Shows the tips. /// </summary> /// <param name="rectControl">The rect control.</param> /// <param name="strMsg">The string MSG.</param> /// <param name="location">The location.</param> /// <param name="background">The background.</param> /// <param name="foreColor">Color of the fore.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="autoCloseTime">The automatic close time.</param> /// <param name="parentForm">父窗体</param> /// <param name="blnTopMost">是否置顶</param> /// <returns>FrmAnchorTips.</returns> public static FrmAnchorTips ShowTips( Rectangle rectControl, string strMsg, AnchorTipsLocation location = AnchorTipsLocation.RIGHT, Color?background = null, Color?foreColor = null, int fontSize = 10, int autoCloseTime = 5000, Control parentControl = null, bool blnTopMost = true) { FrmAnchorTips frm = new FrmAnchorTips(rectControl, strMsg, location, background, foreColor, fontSize, autoCloseTime); frm.TopMost = blnTopMost; frm.Show(parentControl); if (parentControl != null) { parentControl.Disposed += (a, b) => { }; parentControl.VisibleChanged += (a, b) => { try { Control c = a as Control; if (CheckControlClose(c)) { frm.Close(); } } catch (Exception ex) { } }; parentControl.ParentChanged += (a, b) => { }; parentControl.HandleDestroyed += (a, b) => { }; } return(frm); }
/// <summary> /// 功能描述:构造函数 English:Constructor /// 作 者:HZH /// 创建日期:2019-08-29 15:27:51 /// 任务编号: /// </summary> /// <param name="rectControl">停靠区域</param> /// <param name="strMsg">消息</param> /// <param name="location">显示方位</param> /// <param name="background">背景色</param> /// <param name="foreColor">文字颜色</param> /// <param name="fontSize">文字大小</param> /// <param name="autoCloseTime">自动关闭时间,当<=0时不自动关闭</param> private FrmAnchorTips( Rectangle rectControl, string strMsg, AnchorTipsLocation location = AnchorTipsLocation.RIGHT, Color?background = null, Color?foreColor = null, int fontSize = 10, int autoCloseTime = 5000) { InitializeComponent(); Graphics g = this.CreateGraphics(); Font _font = new Font("微软雅黑", fontSize); Color _background = background == null?Color.FromArgb(255, 77, 58) : background.Value; Color _foreColor = foreColor == null ? Color.White : foreColor.Value; System.Drawing.SizeF sizeText = g.MeasureString(strMsg, _font); g.Dispose(); var formSize = new Size((int)sizeText.Width + 20, (int)sizeText.Height + 20); if (formSize.Width < 20) { formSize.Width = 20; } if (formSize.Height < 20) { formSize.Height = 20; } if (location == AnchorTipsLocation.LEFT || location == AnchorTipsLocation.RIGHT) { formSize.Width += 20; } else { formSize.Height += 20; } #region 获取窗体path English:Get the form path GraphicsPath path = new GraphicsPath(); Rectangle rect; switch (location) { case AnchorTipsLocation.TOP: rect = new Rectangle(1, 1, formSize.Width - 2, formSize.Height - 20 - 1); this.Location = new Point(rectControl.X + (rectControl.Width - rect.Width) / 2, rectControl.Y - rect.Height - 20); break; case AnchorTipsLocation.RIGHT: rect = new Rectangle(20, 1, formSize.Width - 20 - 1, formSize.Height - 2); this.Location = new Point(rectControl.Right, rectControl.Y + (rectControl.Height - rect.Height) / 2); break; case AnchorTipsLocation.BOTTOM: rect = new Rectangle(1, 20, formSize.Width - 2, formSize.Height - 20 - 1); this.Location = new Point(rectControl.X + (rectControl.Width - rect.Width) / 2, rectControl.Bottom); break; default: rect = new Rectangle(1, 1, formSize.Width - 20 - 1, formSize.Height - 2); this.Location = new Point(rectControl.X - rect.Width - 20, rectControl.Y + (rectControl.Height - rect.Height) / 2); break; } int cornerRadius = 2; path.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);//左上角 #region 边 if (location == AnchorTipsLocation.BOTTOM) { path.AddLine(rect.X + cornerRadius, rect.Y, rect.Left + rect.Width / 2 - 10, rect.Y); //上 path.AddLine(rect.Left + rect.Width / 2 - 10, rect.Y, rect.Left + rect.Width / 2, rect.Y - 19); //上 path.AddLine(rect.Left + rect.Width / 2, rect.Y - 19, rect.Left + rect.Width / 2 + 10, rect.Y); //上 path.AddLine(rect.Left + rect.Width / 2 + 10, rect.Y, rect.Right - cornerRadius * 2, rect.Y); //上 } else { path.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);//上 } #endregion path.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);//右上角 #region 右边 if (location == AnchorTipsLocation.LEFT) { path.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height / 2 - 10); //右 path.AddLine(rect.Right, rect.Y + rect.Height / 2 - 10, rect.Right + 19, rect.Y + rect.Height / 2); //右 path.AddLine(rect.Right + 19, rect.Y + rect.Height / 2, rect.Right, rect.Y + rect.Height / 2 + 10); //右 path.AddLine(rect.Right, rect.Y + rect.Height / 2 + 10, rect.Right, rect.Y + rect.Height - cornerRadius * 2); //右 } else { path.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);//右 } #endregion path.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);//右下角 #region 边 if (location == AnchorTipsLocation.TOP) { path.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.Left + rect.Width / 2 + 10, rect.Bottom); path.AddLine(rect.Left + rect.Width / 2 + 10, rect.Bottom, rect.Left + rect.Width / 2, rect.Bottom + 19); path.AddLine(rect.Left + rect.Width / 2, rect.Bottom + 19, rect.Left + rect.Width / 2 - 10, rect.Bottom); path.AddLine(rect.Left + rect.Width / 2 - 10, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom); } else { path.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom); } #endregion path.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);//左下角 #region 左边 if (location == AnchorTipsLocation.RIGHT) { path.AddLine(rect.Left, rect.Y + cornerRadius * 2, rect.Left, rect.Y + rect.Height / 2 - 10); //左 path.AddLine(rect.Left, rect.Y + rect.Height / 2 - 10, rect.Left - 19, rect.Y + rect.Height / 2); //左 path.AddLine(rect.Left - 19, rect.Y + rect.Height / 2, rect.Left, rect.Y + rect.Height / 2 + 10); //左 path.AddLine(rect.Left, rect.Y + rect.Height / 2 + 10, rect.Left, rect.Y + rect.Height - cornerRadius * 2); //左 } else { path.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);//左 } #endregion path.CloseFigure(); #endregion Bitmap bit = new Bitmap(formSize.Width, formSize.Height); this.Size = formSize; #region 画图 English:Drawing Graphics gBit = Graphics.FromImage(bit); gBit.SetGDIHigh(); gBit.FillPath(new SolidBrush(_background), path); gBit.DrawString(strMsg, _font, new SolidBrush(_foreColor), rect.Location + new Size(10, 10)); gBit.Dispose(); #endregion SetBits(bit); if (autoCloseTime > 0) { Timer t = new Timer(); t.Interval = autoCloseTime; t.Tick += (a, b) => { this.Close(); }; t.Enabled = true; } }