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


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

    效果图:

    生成的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:	mp.ico", Stm.ToArray)
                Stm.Close()
                Dim Lnk As New DSAPI.文件.快捷方式 With
                {
                           .图标路径 = "c:	mp.ico",
                           .文件路径或URL = "https://www.cnblogs.com/dylike/",
                           .提示说明 = "有新的消息"
                }
                Lnk.保存快捷方式到(String.Concat(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "程序.lnk"))
            Catch
            End Try
        End Sub
    

      

  • 相关阅读:
    Python全栈之机器学习参考笔记
    每个Kaggle冠军的获胜法门:揭秘Python中的模型集成
    logback配置文件
    浅谈Spring中的IOC容器
    JavaWeb三大组件之Servlet
    JavaWeb三大组件之Filter
    常用执行计划操作符
    Linux环境下Redis集群实践
    SQL事物隔离级别
    任务调度框架-Quartz.Net
  • 原文地址:https://www.cnblogs.com/dylike/p/10677331.html
Copyright © 2020-2023  润新知