12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using System.Text;
- using System.Drawing;
- using System.ComponentModel;
- namespace LYFZ.ComponentLibrary
- {
- public class ExToolTip : System.Windows.Forms.ToolTip
- {
- public ExToolTip()
- {
- this.OwnerDraw = true;
- this.Draw += ExToolTip_Draw;
- this.Popup += ExToolTip_Popup;
- }
- Font toolTipFont = new Font("微软雅黑", 16);
- /// <summary>
- /// 设置提示文字大小
- /// </summary>
- [DescriptionAttribute("设置提示文字大小"), CategoryAttribute("组件扩展属性")]
- public Font ToolTipFont
- {
- get { return toolTipFont; }
- set { toolTipFont = value; }
- }
- void ExToolTip_Popup(object sender, System.Windows.Forms.PopupEventArgs e)
- {
- try
- {
- if (e.AssociatedControl.Tag != null && e.AssociatedControl.Tag.GetType() == typeof(ExToolTipText))
- {
- ExToolTipText tooltipText = (ExToolTipText)e.AssociatedControl.Tag;
- //e.ToolTipSize = System.Windows.Forms.TextRenderer.MeasureText(tooltipText.ToolTipText, toolTipFont);
- //e.ToolTipSize = new Size(Convert.ToInt32(e.ToolTipSize.Width * 0.5), Convert.ToInt32(e.ToolTipSize.Height * 0.5));
- Size si = System.Windows.Forms.TextRenderer.MeasureText(tooltipText.ToolTipText, toolTipFont);
- e.ToolTipSize = new Size(si.Width + 10, si.Height + 10);
- }
- }
- catch
- {
- }
- }
- void ExToolTip_Draw(object sender, System.Windows.Forms.DrawToolTipEventArgs e)
- {
- e.DrawBackground();
- e.DrawBorder();
- e.Graphics.DrawString(e.ToolTipText, toolTipFont, Brushes.Black, new PointF(2, 2));
- }
- }
- /// <summary>
- /// 工具提示文本对象
- /// </summary>
- public class ExToolTipText
- {
- public ExToolTipText(string toolTipText, object tag = null)
- {
- this.tag = tag;
- this.toolTipText = toolTipText;
- }
- object tag = null;
- public object Tag
- {
- get { return tag; }
- set { tag = value; }
- }
- string toolTipText = "";
- /// <summary>
- /// 自定义工具提示文字
- /// </summary>
- public string ToolTipText
- {
- get { return toolTipText; }
- set { toolTipText = value; }
- }
- }
- }
|