icon refuses to work anywhere but my documents

cdoverlaw

Well-known member
Joined
Oct 11, 2003
Messages
146
My program uses a notifyicon but if the icon isnt in the my documents folder it wont work
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        NotifyIcon1.Icon = New _
   System.Drawing.Icon(System.Environment.GetFolderPath _
   (System.Environment.SpecialFolder.Personal) _
   & "/Icon.ico")
        NotifyIcon1.Visible = True
        NotifyIcon1.Text = "WHM & CP Launcher"

    End Sub
how can i get it to work where ever the program is installed

Jonathan
 
Just a rehash of the link I posted...
Code:
Dim ico As Icon

ico = New Icon(([Assembly].GetExecutingAssembly().GetManifestResourceStream("WindowsApplication1.Icon1.ico")))
Me.Icon = ico

you will need to change WindowsApplication1 to the namespace for your application and Icon1.ico to whatever the icon is called.
Also add
Code:
Imports System.Reflection
to the top of the module
 
it says
Code:
name Assembly not declared
what is the problem with this

UPDATE:
I cant work out how to get this to work, i basically need all files to work from whatever directory they are in, they dont have to be embedded i just want it to work
 
Last edited by a moderator:
Did you add the imports statement I mentioned as well - it should work if you did.
Also did you try using Application.SartupPath and putting them in the same directory as the executable? Either of those ways should work.

If you are having problems then posting the code in question or the errors raised will give people more chance to help.
 
Basicly i dont understand where to add that code
in the subroutine which regards this notify icon I have currently
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        NotifyIcon1.Icon = New _
   System.Drawing.Icon(System.Environment.GetFolderPath _
   (System.Environment.SpecialFolder.Personal) _
   & "/Icon.ico")
        NotifyIcon1.Visible = True
        NotifyIcon1.Text = "WHM & CP Launcher"
    End Sub
 
Last edited by a moderator:
You could replace your form_load code with the code from above
Code:
Dim ico As Icon

ico = New Icon(([Assembly].GetExecutingAssembly().GetManifestResourceStream("WindowsApplication1.Icon1.ico")))
Me.Icon = ico

or if you just want to drop them in the application directory use
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        NotifyIcon1.Icon = New _
   System.Drawing.Icon(Application.StartupPath & "\Icon1.ico")
        NotifyIcon1.Visible = True
        NotifyIcon1.Text = "WHM & CP Launcher"
    End Sub

although the second way isnt always 100% reliable - a short-cut could have an alternate startup directory which would break this.
 
Back
Top