473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Icon as embedded resource

I'm fairly new to VB .NET and programming in general, and I want to
give my program its own icon without it being a separate file. I have
the icon as part of the project, and its Build Action is set to
Embedded Resource. I've searched high and low for the code that will
actually make it load as the program's default icon, but nothing I've
found works. Can someone give me the code necessary to do this?

Nov 21 '05 #1
11 5543
m
Uzytkownik "Garrett"
<thisisarealaddressbutidontuseit@abcdefghijklmnopq rstuvwxyzabcdefghijklmnopq
rstuvwxyzabcdefghijk.com> napisal w wiadomosci
news:11**********************@f14g2000cwb.googlegr oups.com...
I'm fairly new to VB .NET and programming in general, and I want to
give my program its own icon without it being a separate file. I have
the icon as part of the project, and its Build Action is set to
Embedded Resource. I've searched high and low for the code that will
actually make it load as the program's default icon, but nothing I've
found works. Can someone give me the code necessary to do this?


here you are

'''<summary>
''' Reads icon from embeded resource
''' </summary>
Public Shared Function readResourceIcon(ByVal IconName As String) As
Icon
' Get our assembly.
Dim executing_assembly As System.Reflection.Assembly = _
fMain.GetType.Assembly.GetEntryAssembly()

Dim picture_stream As Stream
Dim iconReaded As Icon

picture_stream =
executing_assembly.GetManifestResourceStream(IconN ame)
If Not (picture_stream Is Nothing) Then
iconReaded = New Icon(picture_stream)
picture_stream.Close()
Return iconReaded
End If
End Function

I hope this helps
Mario
Nov 21 '05 #2
Bob
Right-click on your project in Solution Explorer and select 'Properties'.
Click on the 'build' item under 'common properties'. You will be able to
chose an application icon there. If your project builds a DLL you will need
to temporarily set it to an EXE first.

HTH,
Bob

"Garrett"
<thisisarealaddressbutidontuseit@abcdefghijklmnopq rstuvwxyzabcdefghijklmnopq
rstuvwxyzabcdefghijk.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I'm fairly new to VB .NET and programming in general, and I want to
give my program its own icon without it being a separate file. I have
the icon as part of the project, and its Build Action is set to
Embedded Resource. I've searched high and low for the code that will
actually make it load as the program's default icon, but nothing I've
found works. Can someone give me the code necessary to do this?

Nov 21 '05 #3
Thanks for your help, but I'm getting these errors with the code:

"Name 'fMain' is not declared."
"Type 'Stream' is not defined."
And, for Return iconReaded: "Value of type 'System.Drawing.Icon' cannot
be converted to '1-dimensonal array of System.Drawing.Icon'."

Nov 21 '05 #4
Try the below functions for getting different types of embedded images.

Imports System
Imports System.Reflection
Imports System.Drawing
Imports System.Windows.Forms

Public Class Resources
'WARNING: Icon and Image Names are Case Sensistive
Private Shared Function AssemblyName() As String
Static v_AssemblyName As String
If v_AssemblyName Is Nothing Then v_AssemblyName =
System.Reflection.Assembly.GetExecutingAssembly(). GetName.Name & "."
Return v_AssemblyName
End Function
Public Shared Function GetIcon(ByVal IconName As String) As Icon
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim v_name As String = IconName
If InStr(v_name.ToLower, ".ico") <= 0 Then v_name = v_name & ".ico"
Dim Name As String = AssemblyName() & v_name
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Icon(s)
s.Close()
End If
End Function

Public Shared Function GetImage(ByVal BitMapName As String) As Bitmap
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim v_name As String = BitMapName
If InStr(v_name.ToLower, ".bmp") <= 0 Then v_name = v_name & ".bmp"
Dim Name As String = AssemblyName() & v_name
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Bitmap(s)
s.Close()
End If
End Function

Public Shared Function GetCursor(ByVal CursorName As String) As Cursor
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim v_name As String = CursorName
If InStr(v_name.ToLower, ".cur") <= 0 Then v_name = v_name & ".cur"
Dim Name As String = AssemblyName() & v_name
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Cursor(s)
s.Close()
End If
End Function
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class

"Garrett" wrote:
I'm fairly new to VB .NET and programming in general, and I want to
give my program its own icon without it being a separate file. I have
the icon as part of the project, and its Build Action is set to
Embedded Resource. I've searched high and low for the code that will
actually make it load as the program's default icon, but nothing I've
found works. Can someone give me the code necessary to do this?

Nov 21 '05 #5
Try the below functions for getting different types of embedded images.

Imports System
Imports System.Reflection
Imports System.Drawing
Imports System.Windows.Forms

Public Class Resources
'WARNING: Icon and Image Names are Case Sensistive
Private Shared Function AssemblyName() As String
Static v_AssemblyName As String
If v_AssemblyName Is Nothing Then v_AssemblyName =
System.Reflection.Assembly.GetExecutingAssembly(). GetName.Name & "."
Return v_AssemblyName
End Function
Public Shared Function GetIcon(ByVal IconName As String) As Icon
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim v_name As String = IconName
If InStr(v_name.ToLower, ".ico") <= 0 Then v_name = v_name & ".ico"
Dim Name As String = AssemblyName() & v_name
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Icon(s)
s.Close()
End If
End Function

Public Shared Function GetImage(ByVal BitMapName As String) As Bitmap
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim v_name As String = BitMapName
If InStr(v_name.ToLower, ".bmp") <= 0 Then v_name = v_name & ".bmp"
Dim Name As String = AssemblyName() & v_name
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Bitmap(s)
s.Close()
End If
End Function

Public Shared Function GetCursor(ByVal CursorName As String) As Cursor
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim v_name As String = CursorName
If InStr(v_name.ToLower, ".cur") <= 0 Then v_name = v_name & ".cur"
Dim Name As String = AssemblyName() & v_name
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
Return New Cursor(s)
s.Close()
End If
End Function
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class

"Garrett" wrote:
I'm fairly new to VB .NET and programming in general, and I want to
give my program its own icon without it being a separate file. I have
the icon as part of the project, and its Build Action is set to
Embedded Resource. I've searched high and low for the code that will
actually make it load as the program's default icon, but nothing I've
found works. Can someone give me the code necessary to do this?

Nov 21 '05 #6
Dennis,

Visual Studio won't let me Dim anything as type [Assembly] ("Type
[Assembly] is not defined"). Other than that, it doesn't catch any
errors with your code.

Nov 21 '05 #7
Dennis,

Visual Studio won't let me Dim anything as type [Assembly] ("Type
[Assembly] is not defined"). Other than that, it doesn't catch any
errors with your code.

Nov 21 '05 #8
I am using VB.Net 2003 Professional Version and the following is directly out
of the help sheet on "Assembly" Class:

Public Class LoadInvoke
Public Shared Sub Main(ByVal args() As String)
Dim a As [Assembly] = [Assembly].LoadFrom(args(0))
Dim mytypes As Type() = a.GetTypes()

Are you sure you have the correct imports statements? Also, you might check
the references. You should have at least the following:

System
System.Data
System.Drawing
System.Management
System.XML
System.Widnows.Forms

You may not need all of these but these are the references I have in the
module containing the resource routines.

"Garrett" wrote:
Dennis,

Visual Studio won't let me Dim anything as type [Assembly] ("Type
[Assembly] is not defined"). Other than that, it doesn't catch any
errors with your code.

Nov 21 '05 #9
I am using VB.Net 2003 Professional Version and the following is directly out
of the help sheet on "Assembly" Class:

Public Class LoadInvoke
Public Shared Sub Main(ByVal args() As String)
Dim a As [Assembly] = [Assembly].LoadFrom(args(0))
Dim mytypes As Type() = a.GetTypes()

Are you sure you have the correct imports statements? Also, you might check
the references. You should have at least the following:

System
System.Data
System.Drawing
System.Management
System.XML
System.Widnows.Forms

You may not need all of these but these are the references I have in the
module containing the resource routines.

"Garrett" wrote:
Dennis,

Visual Studio won't let me Dim anything as type [Assembly] ("Type
[Assembly] is not defined"). Other than that, it doesn't catch any
errors with your code.

Nov 21 '05 #10
I'm using Microsoft Development Environment 2003 with .NET Framework
1.1. Not sure what you mean by imports statements - can't find any. I
have all the references you mentioned except System.Management.

Nov 21 '05 #11
By Imports, I mean the following at the top of your module, form, etc.
before any Public Class, etc. statements.

Imports System
Imports System.Reflection
Imports System.Drawing
Imports System.Windows.Forms
Also, you need to add a reference to System.Management

"Garrett" wrote:
I'm using Microsoft Development Environment 2003 with .NET Framework
1.1. Not sure what you mean by imports statements - can't find any. I
have all the references you mentioned except System.Management.

Nov 21 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ed Sutton | last post by:
What's the trick to loading an icon from the embedded resources? Here are the steps I have taken: ------------------------- 1 - I added a file named "FOLDER01.ICO" to my solution project 2 - I...
4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
2
by: Jack | last post by:
I was learning Windows programming in C# using Charles Petzold book, but this book was written for the older version of .NET. The example of using icon from embedded resource fails to work when...
3
by: Wayne | last post by:
I currently have an app whose Icon I am setting. I want to set the icons in my forms at run time to that of the application icon. How do I retrieve the application Icon so that I can use it for my...
8
by: Adrian | last post by:
How do I put an icon on a form using code? Thank you.
0
by: carl.manaster | last post by:
Hi, In <http://groups-beta.google.com/group/microsoft.public.dotnet.languages.csharp/msg/05abaf8460c61859>, back in 2003, "SleazySt" wrote that > Unfortunately, C# projects can't have...
2
by: Amjad | last post by:
Hi, I'm using the NotifyIcon to process some text files in the background periodically. I want to display one icon in the task bar when the program is in stand by mode, and I want to display...
6
by: farseer | last post by:
Hi, I created a new resouce ("app.resx") in my project and added an icon to this resource with name "IL_ICON". I would like to use this resource in some unmanaged code, in particular, with the...
13
by: Lou | last post by:
if I add a new item (Solution Items) to my project and its an icon(.ico), how can I reference that file when I am coding, Do I have to also add it to an image control, I don't want the file to be...
4
by: randy1200 | last post by:
I have a Windows application that previously had the company logo "MyCompany.ico" added to the upper left-most corner. The company has since issued a new version of "MyCompany.ico" that looks...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.