winform 自定义tooltip字体,样式适合各种控件(listview,datagridview)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了winform 自定义tooltip字体,样式适合各种控件(listview,datagridview)相关的知识,希望对你有一定的参考价值。
参考技术A 先定义tooltip的操作类public static class TooltipToolV2
/// <summary>
/// 为控件提供Tooltip
/// </summary>
/// <param name="control">控件</param>
/// <param name="tip">ToolTip</param>
/// <param name="message">提示消息</param>
public static void ShowTooltip(this Control control, ToolTip tip, string message)
Point _mousePoint = Control.MousePosition;
int _x = control.PointToClient(_mousePoint).X;
int _y = control.PointToClient(_mousePoint).Y;
tip.Show(message, control, _x, _y);
tip.Active = true;
/// <summary>
/// 为控件提供Tooltip
/// </summary>
/// <param name="control">控件</param>
/// <param name="tip">ToolTip</param>
/// <param name="message">提示消息</param>
/// <param name="durationTime">保持提示的持续时间</param>
public static void ShowTooltip(this Control control, ToolTip tip, string message, int durationTime)
Point _mousePoint = Control.MousePosition;
int _x = control.PointToClient(_mousePoint).X;
int _y = control.PointToClient(_mousePoint).Y;
tip.Show(message, control, _x, _y, durationTime);
tip.Active = true;
public static void HidenTooltip(this Control control, ToolTip tip)
tip.Hide(control);
/// <summary>
/// 为控件提供Tooltip
/// </summary>
/// <param name="control">控件</param>
/// <param name="tip">ToolTip</param>
/// <param name="message">提示消息</param>
/// <param name="xoffset">水平偏移量</param>
/// <param name="yoffset">垂直偏移量</param>
public static void ShowTooltip(this Control control, ToolTip tip, string message, int xoffset, int yoffset)
Point _mousePoint = Control.MousePosition;
int _x = control.PointToClient(_mousePoint).X;
int _y = control.PointToClient(_mousePoint).Y;
tip.Show(message, control, _x + xoffset, _y + yoffset);
tip.Active = true;
/// <summary>
/// 为控件提供Tooltip
/// </summary>
/// <param name="control">控件</param>
/// <param name="tip">ToolTip</param>
/// <param name="message">提示消息</param>
/// <param name="xoffset">水平偏移量</param>
/// <param name="yoffset">垂直偏移量</param>
/// <param name="durationTime">保持提示的持续时间</param>
public static void ShowTooltip(this Control control, ToolTip tip, string message, int xoffset, int yoffset, int durationTime)
Point _mousePoint = Control.MousePosition;
int _x = control.PointToClient(_mousePoint).X;
int _y = control.PointToClient(_mousePoint).Y;
tip.Show(message, control, _x + xoffset, _y + yoffset, durationTime);
tip.Active = true;
然后在需要自定义tooltip的页面,引入tooltip,定义初始化方法
string schedulerToolTip = "";
private void toolTipSet(string tipText)
schedulerToolTip = tipText;
toolTip1.OwnerDraw = true;
toolTip1.Popup -= ToolTip_Popup;
toolTip1.Popup += ToolTip_Popup;
toolTip1.Draw -= ToolTip_Draw;
toolTip1.Draw += ToolTip_Draw;
void ToolTip_Popup(object sender, PopupEventArgs e)
e.ToolTipSize = TextRenderer.MeasureText(schedulerToolTip, new Font("微软雅黑", 14.0f));
void ToolTip_Draw(object sender, DrawToolTipEventArgs e)
using (e.Graphics)
Font f = new Font("微软雅黑", 14.0f);
e.DrawBackground();
e.DrawBorder();
e.Graphics.DrawString(e.ToolTipText, f, Brushes.Black, new Point(2, 2));
在需要操作的方法里面调用
private void dgv_CurTechnic_CellClick(object sender, DataGridViewCellEventArgs e)
if (e.ColumnIndex < 0 || e.RowIndex < 0) return;
var tempText= (dgv_CurTechnic.Rows[e.RowIndex].Cells[e.ColumnIndex].Value ?? string.Empty).ToString();
string resultString = "";
int i = 0;
int size = 12;
// 此处为了换行,适当参考
for (; i< tempText.Length / size; i++)
resultString += tempText.Substring(i* size, size) + Environment.NewLine;
resultString += tempText.Substring(i * size, resulttxt.Length - i * size);
toolTipSet(resultString);
dgv_CurTechnic.ShowTooltip(toolTip1, resultString, 55000);
private void dgv_CurTechnic_Leave(object sender, EventArgs e)
dgv_CurTechnic.HidenTooltip(toolTip1);
iOS 添加自定义文字字体样式
1,导入ttf格式的字体到项目中
2.在info添加配置
3,双击字体,可以得到字体名(家族名)
4,可以在程序启动时打印出程序里面的所有字体名
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { rray *familyNames = [UIFont familyNames]; for( NSString *familyName in familyNames ){ printf( "Family: %s \n", [familyName UTF8String] ); NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName]; for( NSString *fontName in fontNames ){ printf( "\tFont: %s \n", [fontName UTF8String] ); } } return YES;
5,根据我们添加的字体的家族名,搜索到对应的成员名
6,设置字体,不用填写后缀名
[titleBtn.titleLabel setFont:[UIFont fontWithName:@"FZZDHJW--GB1-0" size:15]];
以上是关于winform 自定义tooltip字体,样式适合各种控件(listview,datagridview)的主要内容,如果未能解决你的问题,请参考以下文章
vue 里怎么使用 echarts 实现地图自动轮播功能自定义 tooltip 悬浮位置提示自定义 label 标签位置样式?
winform 默认的窗体边框颜色是黄色的? 而且为啥程序运行了后 窗体大小 控件间距 还有字体 感觉不一样?