AntdUI 中很多反馈/弹层不是普通控件,而是静态类方法:Message、Notification、Modal、Drawer、Popover、Tooltip、Tour、Preview。它们通常通过 open(...) 或 success/info/warn/error(...) 方法弹出。
静态弹层需要一个 AntdUI 可识别的所有者窗口。推荐在 aardio 窗口里放一个 custom 宿主,然后创建并嵌入 AntdUI.BaseForm,再把这个 baseForm 传给 Message.Config、Notification.Config、Modal.Config、Drawer.Config 等。
import win.ui;
import dotNet;
import dotNet.AntdUI;
import System.Windows.Forms;
/*DSG{{*/
var winform = win.form(text="AntdUI 弹层";right=620;bottom=360)
winform.add(
btn={cls="button";text="提示";left=40;top=40;right=180;bottom=76;z=2};
customBase={cls="custom";left=40;top=316;right=337;bottom=344;hide=1;z=1}
)
/*}}*/
// 构造一个 AntdUI / WinForms 所有者窗口(可设为隐藏不显示),供静态弹层定位与挂载。
var baseForm = AntdUI.BaseForm(winform.customBase);
winform.btn.oncommand = function(){
var cfg = AntdUI.Message.Config(baseForm,"保存成功",AntdUI.TType.Success);
cfg.AutoClose = 3;
cfg.Align = AntdUI.TAlignFrom.Top;
AntdUI.Message.open(cfg);
}
winform.show();
win.loopMessage();
BaseForm本质上是 .NETSystem.Windows.Forms.Form,符合 AntdUI 静态弹层的 owner/target 需求;普通 aardiowin.form或窗口句柄不等价于 AntdUI 期望的 WinFormsForm。
适合短反馈:保存成功、删除失败、加载中。
常用方法:
AntdUI.Message.open(config):配置对象方式,推荐。AntdUI.Message.success/info/warn/error(...):快捷提示。AntdUI.Message.loading(...):加载提示,常返回可继续更新状态的对象。close_all() / close_id(id) / contains(id):关闭或查询提示。常用配置字段:Target、Text、Icon、AutoClose、ClickClose、TopMost、Align、ShowInWindow、MaxWidth。
适合更明显的通知卡片,可包含标题、正文、状态图标、关闭按钮与链接操作。
var cfg = AntdUI.Notification.Config(baseForm,"任务完成","文件已导出。",AntdUI.TType.Success,AntdUI.TAlignFrom.TR);
cfg.AutoClose = 5;
cfg.ShowInWindow = true;
AntdUI.Notification.open(cfg);
常用配置字段:ID、Title、Text、Icon、Align、Radius、AutoClose、ClickClose、CloseIcon、ShowInWindow、EnableSound、OnClose。
适合需要用户确认的场景:删除确认、提交前确认、展示复杂内容。
var cfg = AntdUI.Modal.Config(baseForm,"删除确认","确定删除这条记录吗?",AntdUI.TType.Warn);
cfg.OkText = "删除";
cfg.CancelText = "取消";
cfg.MaskClosable = false;
var result = AntdUI.Modal.open(cfg);
常用配置字段:Title、Content、Icon、Width、Mask、MaskClosable、CloseIcon、Keyboard、OkText、CancelText、OkType、OnOk、Btns、OnBtns、Resizable。
复杂内容可传入 System.Windows.Forms.Control 或 Modal.TextLine[]。
适合从侧边滑出的表单、详情页、设置面板。
import System.Windows.Forms;
import System.Drawing;
var panel = System.Windows.Forms.Panel();
panel.Size = System.Drawing.Size(360,240);
var cfg = AntdUI.Drawer.Config(baseForm,panel);
cfg.Align = AntdUI.TAlignMini.Right;
cfg.Padding = 24;
AntdUI.Drawer.open(cfg);
常用配置字段:Form、Content、Align、Padding、Mask、MaskClosable、Dispose、OnLoad、OnClose、DisplayDelay。
Popover 依附在某个 WinForms/AntdUI 控件上,适合显示轻量详情、操作说明或短操作入口。
var cfg = AntdUI.Popover.Config(btn,"订单提醒","您有 3 条待处理订单。");
cfg.SetArrow(AntdUI.TAlign.Bottom).SetAutoClose(0).SetPadding(16,12);
AntdUI.Popover.open(cfg);
Content 可为字符串、WinForms 控件或 Popover.TextRow[]。多段文本示例:
import dotNet;
import System.Drawing;
var rows = dotNet.createArray(AntdUI.Popover.TextRow,2);
rows.SetValue(AntdUI.Popover.TextRow("查看"),0);
rows.SetValue(AntdUI.Popover.TextRow("详情",2,0xFF0000FF),1);
AntdUI.Popover.open(btn,rows,AntdUI.TAlign.BL);
常见注意点:目标必须是 WinForms/AntdUI 控件,普通 aardio 按钮不能直接作为 Popover 目标。
Tooltip 用于非常短的解释性文字,可直接打开,也可用配置对象控制宽度、圆角、箭头和颜色。
var cfg = AntdUI.Tooltip.Config(btn,"这是一个文字提示");
cfg.SetArrow(AntdUI.TAlign.Top).SetRadius(8).SetCustomWidth(180);
AntdUI.Tooltip.open(cfg);
如果需要标题、复杂内容或可点击内容,请改用 Popover。
Preview 是静态图片预览弹层,调用 AntdUI.Preview.open(cfg) 打开。ImagePreview 是普通控件,嵌入在窗体指定区域内持续显示图片集合。import System.Drawing;
var image = System.Drawing.Bitmap(160,90);
var cfg = AntdUI.Preview.Config(baseForm,image);
cfg.SetFit(AntdUI.TFit.Contain).SetKeyboard(true);
AntdUI.Preview.open(cfg);
Preview.Config 的 owner 是 WinForms Form,在 aardio 中仍建议使用 AntdUI.BaseForm。
Tour 用于分步骤引导用户认识界面。每一步由 StepCall 回调决定要高亮的控件或区域。
var cfg = AntdUI.Tour.Config(baseForm,function(result){
if(result.Index == 0){
result.Set(btn);
}
else {
result.Close();
}
});
cfg.SetScale(1.08).SetMaskClosable(true).SetClickNext(true);
AntdUI.Tour.open(cfg);
常见注意点:baseForm 必须是 WinForms Form,result.Set(control) 的 control 也必须是 WinForms/AntdUI 控件。
AntdUI.BaseForm 作为 owner。OK/Error/Warn/Info 或关闭方法。