none
Is it possible to add italics for part of a string in a notifyicon.text property? RRS feed

  • Question

  • e.g. notifyIcon1.Text = "Server Status" + System.Environment.NewLine + "Service: Not Connected";

    Is it possible to Italic just the Not Connected Part?

    Thursday, July 28, 2011 6:20 PM

Answers

All replies

  • Use a richtext control to display your message.

    chanmm


    chanmm
    Friday, July 29, 2011 12:53 AM
  • Hi there, this wont work as its a service, no forms to display a richtextbox, only a tray icon. I've noticed in windows 7 the windows network tray icon has the connected network in italics dependent of the network name that is connected in the notify bubble and just wondered how they do this.
    Sunday, July 31, 2011 9:32 PM
  • Hi

    Notifyicon control doesn't have property or method which could change the font of its text.

    You may implement your own Notifyicon control.

    http://ondotnet.com/pub/a/dotnet/2002/03/18/customcontrols.html


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 2, 2011 7:38 AM
  •  

    Hi pauldevinedotnet,


    Welcome to MSDN forums!

     

    Yes, the standard NotifyIcon control has no such feature to format its Text property.

    1.       You can submit this feedback to Microsoft Connect feedback Center in formal format. Microsoft engineers will evaluate them seriously and report to Product Group.

    http://connect.microsoft.com/VisualStudio/

     

    2.       However, here is a workaround:

    Create a bitmap and draw the italic text to be shown on it, and then convert it to an icon, then assign to NotifyIcon control to show the textual icon.

     

    Code sample:

                String text = "Service: Not Connected";

                Font drawFont = new Font("Arial", 10, FontStyle.Italic);

                SolidBrush drawBrush = new SolidBrush(Color.Black);

                // Create a bitmap and draw text on it

                Bitmap bitmap = new Bitmap(200, 50);

                Graphics graphics = Graphics.FromImage(bitmap);

                graphics.DrawString(text, drawFont, drawBrush, 0, 0);

     

                // Convert the bitmap with text to an Icon

                IntPtr hIcon = bitmap.GetHicon();

                Icon icon = Icon.FromHandle(hIcon);

                //Assign the icon to NotifyIcon

                NotifyIcon m_notifyIcon = new NotifyIcon();

                m_notifyIcon.Text = string.Empty;

                m_notifyIcon.Visible = true;

                m_notifyIcon.Icon = icon;

     

    Track: Animation and Text in System tray using C#

     

    http://blogs.msdn.com/b/abhinaba/archive/2005/09/12/animation-and-text-in-system-tray-using-c.aspx

     

     


    Martin Xie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, August 9, 2011 4:22 AM
    Moderator