zoukankan      html  css  js  c++  java
  • 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
    

      

  • 相关阅读:
    Node学习之(第二章:http模块)
    Node.js学习(第二章:node核心模块--fs)
    Node.js学习(第一章:Node.js安装和模块化理解)
    Node.js学习(第一章:Node.js简介)
    js控制手机震动
    js发送windows提示信息
    js操作一般文件和csv文件
    js操作indexedDB增删改查示例
    js获取用户实时地理位置
    js处理数值和日期本地化
  • 原文地址:https://www.cnblogs.com/dylike/p/10677331.html
Copyright © 2011-2022 走看看