Create NotifyIcon dynamically

CowZ

Member
Joined
Feb 11, 2005
Messages
18
Programming Experience
3-5
Hi,

I just coded a simple CPU-Usage Monitor.
It shows the percent in the Systray. My Question is following one:
Can I create this Icon in my code (e.g. in dependance to the actual usage?)

I tried to do it with a Picturebox, but I found no way to convert the Pictureboxgraphics to an Icon-Object (which is needed for the NotifyIcon)

Cya CowZ
PS: Is this the right forum? might fit into services too...
 
Last edited:
I did something very simular while creating a weather program that showed the temperature in the systray.
Here's the code:
VB.NET:
Public Sub CreateIcon()
    'ToDo: add theming support
    'This color is the color for the Blue WinXP taskbar
    Dim clrBackColor As Color = Color.FromArgb(14, 142, 234)
    Dim btmp As Bitmap = New Bitmap(16, 16)
    Dim g As Graphics = Graphics.FromImage(btmp)
    g.Clear(clrBackColor)
    g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
    Dim TempFont As Font = New System.Drawing.Font("Arial", 6.75!, _
      System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, _
      CType(0, Byte))
    'draw the temperature
    g.DrawString(sTemp, TempFont, Brushes.White, 0, 2)
    'Draw the degrees sign
    g.DrawString("o", New Font("Times New Roman", 5, FontStyle.Regular), _
      brTextColor, 11, -1)
    NotifyIcon1.Icon = Icon.FromHandle(btmp.GetHicon())
End Sub
 
Thanks alot :)

*happy*

nice to have you and this board ;)

edit:
I've got another topic-related question:
How can I create my own Brushes (with my own colors) and how can i set one point (as pset did in vb6)? (I use rectangle right now...)

Cya CowZ
 
Last edited:
There are many brushes already defined in the System.Drawing.Brushes class.
To create your own use code simular to this:
VB.NET:
Dim br As New System.Drawing.SolidBrush(Color.FromArgb(125, 255, 0, 0))
This creates an opaque red brush (alpha=125, red = 255, blue =0, green=0).
There are also different gradient brushes available:
System.Drawing.Drawing2D.LinearGradientBrush
System.Drawing.Drawing2D.PathGradientBrush

Not sure what the pset function did. I never used VB6.
 
Thx alot ;)

The PSet function draw one pixel, as the drawrectangle(b, x, y, 1, 1) funtion does...

Cya CowZ
 
Back
Top