Csharp Override Tool Tip Test
In Csharp Tool Tip Test I did a minimal test on tool tips. I wanted to customize it and found a thread on how to change it at MSDN Social: [1] and in it a class overrides the old tool tip class. It contains a font that is set in the constructor - here is what is looks like with an ugly font:
public class MyTooltip : ToolTip { private Font m_font = null; public MyTooltip(Font font) : base() { m_font = font; this.OwnerDraw = true; this.Draw += new DrawToolTipEventHandler(OnDraw); this.Popup += new PopupEventHandler(OnPopup); } protected override void Dispose(bool disposing) { this.Draw -= new DrawToolTipEventHandler(OnDraw); this.Popup -= new PopupEventHandler(OnPopup); base.Dispose(disposing); } public new bool IsBalloon { set { ; } get { return base.IsBalloon; } } private void OnPopup(object sender, PopupEventArgs e) { SizeF size = e.AssociatedControl.CreateGraphics().MeasureString(this.GetToolTip(e.AssociatedControl), m_font); e.ToolTipSize = new Size(Convert.ToInt32(size.Width), Convert.ToInt32(size.Height)); } private void OnDraw(object sender, DrawToolTipEventArgs e) { DrawToolTipEventArgs newArgs = new DrawToolTipEventArgs(e.Graphics, e.AssociatedWindow, e.AssociatedControl, e.Bounds, e.ToolTipText, this.BackColor, this.ForeColor, m_font); newArgs.DrawBackground(); newArgs.DrawBorder(); newArgs.DrawText(TextFormatFlags.TextBoxControl); } }
One really positive thing is that it integrates nicely into Microsoft Visual Studio:
Download source here: [2] or the executable here: [3]
Also see Csharp Tool Tip Test, Csharp Data Grid View And Tool Tip Test and Csharp Custom Tool Tip.
Csharp Data Grid View And Tool Tip Test for ideas on how to work with tool tips and a data grid view.
Tillhör Kategori Programmering