Icons is Resource Area

  • Thread starter Thread starter John Veldthuis
  • Start date Start date
J

John Veldthuis

I have a program which is using a Notify control for a tray icon. I originally had the icon for this
separate as I have to change it all the time. When the icon was in the directory it worked fine but
since I move it into the Resource area it does not. It looks like the Icon is the full 32x32 on the
tray. Partial code is below. 1st the original and second the changed. I have been unable to find any
way of getting this to work properly.

I assume it is the way I am getting the icon but can't find anything to answer my question.

Cheers


In the Form_Load event I set the notUsage.Icon = My.Resources.trayIcon

-----Original which works

Private Sub SetDiplay()
Dim ico As Icon
Dim s As String
Dim g As Graphics
Dim bmp As Bitmap
Dim per As Double

If notUsage.Visible = False Then Exit Sub
per = Round(percent)
s = per.ToString
ico = New Icon("trayIcon.ico")
ico = New Icon(ico, 16, 16)
bmp = ico.ToBitmap
g = Graphics.FromImage(bmp)
g.Clear(Color.Transparent)
g.DrawString(s, New Font(fontName1, fontSize1, GraphicsUnit.Pixel), New _
SolidBrush(Color.Black), 0, 4)
ico = Drawing.Icon.FromHandle(bmp.GetHicon)
notUsage.Icon = ico
notUsage.Text = "Usage Meter current usage = " + percent.ToString + "%"

End Sub

----- New which does not

Private Sub SetDiplay()
Dim ico As Icon
Dim s As String
Dim g As Graphics
Dim bmp As Bitmap
Dim per As Double

If notUsage.Visible = False Then Exit Sub
per = Round(percent)
s = per.ToString
ico = New Icon(My.Resources.trayIcon, 32, 32)
ico = New Icon(ico, 16, 16)
bmp = ico.ToBitmap
g = Graphics.FromImage(bmp)
g.Clear(Color.Transparent)
g.DrawString(s, New Font(fontName1, fontSize1, GraphicsUnit.Pixel), New _
SolidBrush(Color.Black), 0, 4)
ico = Drawing.Icon.FromHandle(bmp.GetHicon)
notUsage.Icon = ico
notUsage.Text = "Usage Meter current usage = " + percent.ToString + "%"

End Sub
 
Very strange. I have now found it works perfectly if I import the icon as a file but if I create it
in the IDE it does not work.
 
Back
Top