DSAPI 生成桌面图标(带数字)
程序员文章站
2022-04-08 15:48:34
功能:在桌面上创建一个带有指定数字的图标。 效果图: 生成的ICO图标 代码 ......
功能:在桌面上创建一个带有指定数字的图标。
效果图:
生成的ico图标
代码
private sub 生成桌面图标(消息数量 as integer)
try
dim b as new bitmap(my.resources.ico)
using g as graphics = graphics.fromimage(b)
g.clip = new region(new rectanglef(0, 0, b.width, b.height))
dim cnt as string = if(消息数量 > 999, "999+", 消息数量)
dim ft as font = new font("黑体", 24, fontstyle.bold)
dim sz as size = dsapi.图形图像.获取绘制文字所需大小(cnt, ft)
using tb as bitmap = dsapi.图形图像.绘制圆角矩形(sz + new drawing.size(6, 4), 8, color.red, color.darkred, color.transparent)
g.drawimage(tb, new rectangle(b.width - tb.width, 0, tb.width, tb.height), new rectangle(0, 0, tb.width, tb.height), graphicsunit.pixel)
g.textrenderinghint = drawing.text.textrenderinghint.antialias
g.drawstring(cnt, ft, brushes.white, new point(b.width - tb.width + 6, 0))
end using
end using
dim pth as string = system.environment.getfolderpath(environment.specialfolder.desktop)
dim stm as new io.memorystream
dsapi.图形图像.图像生成ico图标(b, 128).save(stm)
io.file.writeallbytes("c:\tmp.ico", stm.toarray)
stm.close()
dim lnk as new dsapi.文件.快捷方式 with
{
.图标路径 = "c:\tmp.ico",
.文件路径或url = "https://www.cnblogs.com/dylike/",
.提示说明 = "有新的消息"
}
lnk.保存快捷方式到(string.concat(system.environment.getfolderpath(environment.specialfolder.desktop), "\程序.lnk"))
catch
end try
end sub
上一篇: 串口编程之端口