Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

My program uses a notifyicon but if the icon isnt in the my documents folder it wont work

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

  • Administrators
Posted

You could put the icon in the applications directory and use a path of Application.StartupPath & "\icon.ico"

 

or alternatively you could embed the icon into the executable.

http://www.xtremedotnettalk.com/showthread.php?s=&threadid=75889&highlight=embedded+resource

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Administrators
Posted

Just a rehash of the link I posted...

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

Imports System.Reflection

to the top of the module

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)

it says

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

Edited by cdoverlaw
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)

Basicly i dont understand where to add that code

in the subroutine which regards this notify icon I have currently

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

Edited by cdoverlaw
  • Administrators
Posted

You could replace your form_load code with the code from above

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

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 isn't always 100% reliable - a short-cut could have an alternate startup directory which would break this.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...