this.toolTip.OwnerDraw = true;
this.toolTip.Draw += new DrawToolTipEventHandler(ToolTipDraw);
this.toolTip.Popup += new PopupEventHandler(ToolTipPopup);
private void ToolTipDraw(object sender, DrawToolTipEventArgs e)
{
e.DrawBackground();
e.DrawBorder();
using (System.Drawing.StringFormat sf = new System.Drawing.StringFormat())
{
sf.Alignment = System.Drawing.StringAlignment.Near;
sf.LineAlignment = System.Drawing.StringAlignment.Center;
sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
sf.FormatFlags = System.Drawing.StringFormatFlags.NoWrap;
sf.Trimming = System.Drawing.StringTrimming.None;
using (System.Drawing.Font f = new System.Drawing.Font("黑体", 12))
{
TextRenderer.DrawText(e.Graphics, e.ToolTipText, f, e.Bounds, System.Drawing.Color.Black, TextFormatFlags.ExternalLeading);
}
}
}
private void ToolTipPopup(object sender, PopupEventArgs e)
{
System.Drawing.Font f1 = new System.Drawing.Font("黑体", 12);
System.Drawing.Size proposedSize = new System.Drawing.Size(int.MaxValue, int.MaxValue);
e.ToolTipSize = TextRenderer.MeasureText(toolTip.GetToolTip(e.AssociatedControl), f1, proposedSize, TextFormatFlags.ExternalLeading);
}
#c# 设置tooptip字体
最新推荐文章于 2023-08-29 09:08:25 发布