当前位置: 移动技术网 > IT编程>开发语言>.net > DSAPI 生成桌面图标(带数字)

DSAPI 生成桌面图标(带数字)

2019年04月10日  | 移动技术网IT编程  | 我要评论

神田留美,日照论坛大众社区,天道外挂

功能:在桌面上创建一个带有指定数字的图标。

效果图:

生成的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

  

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网