Tooltip 是简单的文字提示气泡,适合在鼠标悬停、点击或校验时解释某个控件的含义。
AntdUI 同时提供:
AntdUI.Tooltip():作为控件使用,设置 Text 等属性。AntdUI.Tooltip.open(...):临时打开一个文字提示。AntdUI.Tooltip.Config(...):配置对象方式,推荐在参数较多时使用。import win.ui;
import dotNet.AntdUI;
var winform = win.form(text="AntdUI Tooltip";right=520;bottom=320)
winform.add(host={cls="custom";left=20;top=20;right=180;bottom=60;z=1})
var btn = AntdUI.Button(winform.host);
btn.Text = "显示提示";
btn.Click = function(sender,e){
AntdUI.Tooltip.open(btn,"这是一个文字提示",AntdUI.TAlign.Top);
}
winform.show();
win.loopMessage();
也可以指定目标控件内部的偏移矩形:
import System.Drawing;
AntdUI.Tooltip.open(btn,"局部区域提示",System.Drawing.Rectangle(0,0,80,28),AntdUI.TAlign.Bottom);
var cfg = AntdUI.Tooltip.Config(btn,"支持配置圆角、宽度、箭头方向等");
cfg.SetArrow(AntdUI.TAlign.Top).SetRadius(8).SetCustomWidth(180);
AntdUI.Tooltip.open(cfg);
常用属性:
| 属性 | 说明 |
|---|---|
Control |
依附的 WinForms/AntdUI 控件 |
Text |
提示文本 |
Font |
字体 |
Radius |
圆角 |
ArrowAlign |
箭头方向,AntdUI.TAlign |
ArrowSize |
箭头大小 |
Offset |
目标控件内偏移区域,System.Drawing.Rectangle |
CustomWidth |
自定义宽度 |
Back / Fore |
背景色与前景色 |
常用链式方法:SetOffset、SetFont、SetRadius、SetArrow、SetCustomWidth、SetBack、SetFore。
如果要把 Tooltip 作为普通控件放在宿主中:
var tip = AntdUI.Tooltip(winform.host);
tip.Text = "固定显示的提示文本";
tip.ArrowAlign = AntdUI.TAlign.Top;
tip.Radius = 8;
tip.CustomWidth = 180;
常用属性:Text、LocalizationText、Radius、ArrowAlign、ArrowSize、CustomWidth、Back、Fore。
Tooltip.open 的第一个参数必须是 WinForms/AntdUI 控件。Popover。0xAARRGGBB 数值,例如不透明红色为 0xFFFF0000;不需要调用 System.Drawing.Color.FromArgb(...)。