using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace AnotherToolTipTester { public class ToolTipTesterForm : Form { public ToolTipTesterForm() { InitializeComponent(); } private void m_button_Click(object sender, EventArgs e) { Application.Exit(); } private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { this.m_button = new System.Windows.Forms.Button(); this.tooltip = new MyTooltip(new System.Drawing.Font("Arial", 20.0F)); this.SuspendLayout(); // // tooltip // this.tooltip.OwnerDraw = true; // // m_button // this.m_button.Location = new System.Drawing.Point(12, 12); this.m_button.Name = "m_button"; this.m_button.Size = new System.Drawing.Size(75, 23); this.m_button.TabIndex = 1; this.m_button.Text = "Exit"; this.tooltip.SetToolTip(this.m_button, "Press me to quit."); this.m_button.UseVisualStyleBackColor = true; this.m_button.Click += new System.EventHandler(this.m_button_Click); // // ToolTipTesterForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(192, 73); this.Controls.Add(this.m_button); this.Name = "ToolTipTesterForm"; this.Text = "Another Tool Tip"; this.ResumeLayout(false); } private MyTooltip tooltip; private System.Windows.Forms.Button m_button; } 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); } } static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ToolTipTesterForm()); } } }