Skip to main content

Icon 图标

简介#

图标对象可以由以下方法创建:

export interface IWindow extends IControl {    CreateManagedIcon(icon: IconSource): IIcon;}
export class IconSource {    constructor(resId: number, pixelSizeWhen100Percent: number);}

资源 ID#

在使用图标之前,需要先创建 resource map 以获取资源 id:

examples/unit/app/app-resource

const iconDataMap = {    Open: [path.resolve(__dirname, './FileOpen#0.png')],};const resMap = app.CreateResourceMap(    app,    [16] /* icon size list */,    iconDataMap,);

然后它是这样用的:

window.OnCreateContent((sender) => {    const button = new Button(window);    button.SetText('Open');    button.SetVisualTextLayout(VisualTextLayout.HorzVisualText);
    const iconSource = new IconSource(resMap.Open, 16);    const icon = window.CreateManagedIcon(iconSource);    button.SetVisual(icon);    ...    return true;});