AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Thursday 29 October 2020

Display the text over notify icon image in Windows Application(Win forms, WPF)

 In current post we will discuss how to write text over the image. An application that runs on system tray and occasionally shows notification using the system tray default notifications. Below code could be helpful to modify the icon tray of image.

 NotifyIcon nIcon = new NotifyIcon();

If you want to change the tray icon, create an icon on demand and set it to nIcon.Icon.

  private void AddNotifyTray()
            nIcon.Visible = true;
            nIcon.Icon = GetIcon("3");
            nIcon.Text = "Notifier App";           
            WindowState = System.Windows.WindowState.Minimized;

        public static Icon GetIcon(string text)
            Icon icon = new Icon(@"CT.ico");
            //Create bitmap, kind of canvas
            Bitmap bitmap = new Bitmap(icon.Width + 20, icon.Height);

            System.Drawing.Font drawFont = new System.Drawing.Font("Calibri", 100, System.Drawing.FontStyle.Regular);
            System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);

            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
            graphics.DrawIcon(icon, 0, 0);
            graphics.DrawString(text, drawFont, drawBrush, -20, -20);

            //To Save icon to disk
            //bitmap.Save("icon.ico", System.Drawing.Imaging.ImageFormat.Icon);

            Icon createdIcon = System.Drawing.Icon.FromHandle(bitmap.GetHicon());


            return createdIcon;


Post a Comment

  • Popular Posts
  • Comments