功能:在桌面上建立一個帶有指定數字的圖標。spa
效果圖:blog
生成的ICO圖標ip
代碼ci
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