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 part of the .resx file.
Its like VB6 when I could use load all my images from a resource file.
Lou 13 2050
"Lou" <lo********@comcast.net> schrieb: 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 part of the .resx file. Its like VB6 when I could use load all my images from a resource file.
See:
<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/7f73b72ab0a88452>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
> 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
The easiest thing to do is as follows.
1. Add the .ico file(s) to your project.
2. For each icon file, set the build action to "embedded resource". This
will include the .ico file in your .exe file (my direct experience is only
with windows form .exe files, but I expect this will work with other app
types).
3. In your program, you can get an icon object via the code fragment shown
below. If the name of the icon file xxx.ico, and the name of your app is
yyy, then the name of the icon resource in your .exe file is "yyy.xxx.ico".
dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx
dim MyIcon = New
Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
Now you can set a form's icon like: someform.Icon=MyIcon.
Where do I set the build Action?
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com... 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
The easiest thing to do is as follows.
1. Add the .ico file(s) to your project. 2. For each icon file, set the build action to "embedded resource". This will include the .ico file in your .exe file (my direct experience is only with windows form .exe files, but I expect this will work with other app types). 3. In your program, you can get an icon object via the code fragment shown below. If the name of the icon file xxx.ico, and the name of your app is yyy, then the name of the icon resource in your .exe file is "yyy.xxx.ico".
dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx dim MyIcon = New Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
Now you can set a form's icon like: someform.Icon=MyIcon.
Under "Solutions Items" folder I have 1 file
MyIcon.ico
There is no property to set the build action for that icon that I can find?
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com... 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
The easiest thing to do is as follows.
1. Add the .ico file(s) to your project. 2. For each icon file, set the build action to "embedded resource". This will include the .ico file in your .exe file (my direct experience is only with windows form .exe files, but I expect this will work with other app types). 3. In your program, you can get an icon object via the code fragment shown below. If the name of the icon file xxx.ico, and the name of your app is yyy, then the name of the icon resource in your .exe file is "yyy.xxx.ico".
dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx dim MyIcon = New Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
Now you can set a form's icon like: someform.Icon=MyIcon.
You need to add it to the project and not the solution, as it will compiled
as part of the project assembly.
--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk
---------
Voodoo Programming: Things programmers do that they know shouldn't work but
they try anyway, and which sometimes actually work, such as recompiling
everything. (Karl Lehenbauer)
---------
"Lou" <lo********@comcast.net> wrote in message
news:eT*************@TK2MSFTNGP14.phx.gbl... Under "Solutions Items" folder I have 1 file MyIcon.ico There is no property to set the build action for that icon that I can find?
"AMercer" <AM*****@discussions.microsoft.com> wrote in message news:6E**********************************@microsof t.com... 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
The easiest thing to do is as follows.
1. Add the .ico file(s) to your project. 2. For each icon file, set the build action to "embedded resource". This will include the .ico file in your .exe file (my direct experience is only with windows form .exe files, but I expect this will work with other app types). 3. In your program, you can get an icon object via the code fragment shown below. If the name of the icon file xxx.ico, and the name of your app is yyy, then the name of the icon resource in your .exe file is "yyy.xxx.ico".
dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx dim MyIcon = New Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
Now you can set a form's icon like: someform.Icon=MyIcon.
I managed to add the icon to the proj and set its action to embedded but the
code
dim MyIcon = New
Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
returns null
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com... 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
The easiest thing to do is as follows.
1. Add the .ico file(s) to your project. 2. For each icon file, set the build action to "embedded resource". This will include the .ico file in your .exe file (my direct experience is only with windows form .exe files, but I expect this will work with other app types). 3. In your program, you can get an icon object via the code fragment shown below. If the name of the icon file xxx.ico, and the name of your app is yyy, then the name of the icon resource in your .exe file is "yyy.xxx.ico".
dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx dim MyIcon = New Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
Now you can set a form's icon like: someform.Icon=MyIcon.
"Lou" <lo********@comcast.net> schrieb: Under "Solutions Items" folder I have 1 file MyIcon.ico There is no property to set the build action for that icon that I can find?
Add the icon to the /project/, select it in solution explorer and set the
build action in the property window.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
This method does not seem to work or I can't get it to work?
I added an icon file to my project
I set it to "embedded resource" and added the code below in the proper
format but
it returns null.
There doesn't seem to be anything else to look for?
There must be something missing?
-Lou
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com... 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
The easiest thing to do is as follows.
1. Add the .ico file(s) to your project. 2. For each icon file, set the build action to "embedded resource". This will include the .ico file in your .exe file (my direct experience is only with windows form .exe files, but I expect this will work with other app types). 3. In your program, you can get an icon object via the code fragment shown below. If the name of the icon file xxx.ico, and the name of your app is yyy, then the name of the icon resource in your .exe file is "yyy.xxx.ico".
dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx dim MyIcon = New Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
Now you can set a form's icon like: someform.Icon=MyIcon.
Make sure s contains the fully namespace qualified name of the icon file,
i.e. if the name of your project is Test (assuming you didn't specify a
different namespace) and the name of the file is res.ico, then assign
"Test.res.ico" to s.
--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk
---------
Voodoo Programming: Things programmers do that they know shouldn't work but
they try anyway, and which sometimes actually work, such as recompiling
everything. (Karl Lehenbauer)
---------
"Lou" <lo********@comcast.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... I managed to add the icon to the proj and set its action to embedded but the code dim MyIcon = New Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s)) returns null
"AMercer" <AM*****@discussions.microsoft.com> wrote in message news:6E**********************************@microsof t.com... 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
The easiest thing to do is as follows.
1. Add the .ico file(s) to your project. 2. For each icon file, set the build action to "embedded resource". This will include the .ico file in your .exe file (my direct experience is only with windows form .exe files, but I expect this will work with other app types). 3. In your program, you can get an icon object via the code fragment shown below. If the name of the icon file xxx.ico, and the name of your app is yyy, then the name of the icon resource in your .exe file is "yyy.xxx.ico".
dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx dim MyIcon = New Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
Now you can set a form's icon like: someform.Icon=MyIcon.
Try this class to retrieve embedded resources. Note that the names of the
files are CASE sensitive including the .ico or .bmp endings.
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
--
Dennis in Houston
"Lou" wrote: This method does not seem to work or I can't get it to work?
I added an icon file to my project I set it to "embedded resource" and added the code below in the proper format but it returns null. There doesn't seem to be anything else to look for?
There must be something missing?
-Lou
"AMercer" <AM*****@discussions.microsoft.com> wrote in message news:6E**********************************@microsof t.com... 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
The easiest thing to do is as follows.
1. Add the .ico file(s) to your project. 2. For each icon file, set the build action to "embedded resource". This will include the .ico file in your .exe file (my direct experience is only with windows form .exe files, but I expect this will work with other app types). 3. In your program, you can get an icon object via the code fragment shown below. If the name of the icon file xxx.ico, and the name of your app is yyy, then the name of the icon resource in your .exe file is "yyy.xxx.ico".
dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx dim MyIcon = New Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
Now you can set a form's icon like: someform.Icon=MyIcon.
Thats a handy tip, Thanks!
I'd been trying all sorts of methods for swapping the icons for my
statusbarpanels - this did the job nicely.
Alec
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com... 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
The easiest thing to do is as follows.
1. Add the .ico file(s) to your project. 2. For each icon file, set the build action to "embedded resource". This will include the .ico file in your .exe file (my direct experience is only with windows form .exe files, but I expect this will work with other app types). 3. In your program, you can get an icon object via the code fragment shown below. If the name of the icon file xxx.ico, and the name of your app is yyy, then the name of the icon resource in your .exe file is "yyy.xxx.ico".
dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx dim MyIcon = New Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s))
Now you can set a form's icon like: someform.Icon=MyIcon.
I tried this class and I added code to retrieve the .ico file but it ruturns
"Nothing".
I have added an icon file under my project and it shows up as "Security.ico"
and I have set
the build Action to Embedded Resource. The File Name is "Security.ico"
Here is my form level code that uses your nice class.
Dim Res As New CResource
Dim myIconS As Icon
myIconS = Res.GetIcon("Security")
Me.Icon = myIconS
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:E5**********************************@microsof t.com... Try this class to retrieve embedded resources. Note that the names of the files are CASE sensitive including the .ico or .bmp endings.
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 -- Dennis in Houston
"Lou" wrote:
This method does not seem to work or I can't get it to work?
I added an icon file to my project I set it to "embedded resource" and added the code below in the proper format but it returns null. There doesn't seem to be anything else to look for?
There must be something missing?
-Lou
"AMercer" <AM*****@discussions.microsoft.com> wrote in message news:6E**********************************@microsof t.com... >> 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 > > The easiest thing to do is as follows. > > 1. Add the .ico file(s) to your project. > 2. For each icon file, set the build action to "embedded resource". > This > will include the .ico file in your .exe file (my direct experience is > only > with windows form .exe files, but I expect this will work with other > app > types). > 3. In your program, you can get an icon object via the code fragment > shown > below. If the name of the icon file xxx.ico, and the name of your app > is > yyy, then the name of the icon resource in your .exe file is > "yyy.xxx.ico". > > dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx > dim MyIcon = New > Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s)) > > Now you can set a form's icon like: someform.Icon=MyIcon. >
Some of the errors I"ve made when it returns nothing are:
The Case of either the name or extension was different between the file name
and the name I passed to the class (be sure to check the extension case,
i.e., ICO or ico that they are the same.
When I have multiple projects under one solution, I have to start the
project in a separate solution that I want to add the icon to by itself then
add the icon and set the build to "embedded". Then rebuild the project. Then
restart my solution with multiple projects.
--
Dennis in Houston
"Lou" wrote: I tried this class and I added code to retrieve the .ico file but it ruturns "Nothing". I have added an icon file under my project and it shows up as "Security.ico" and I have set the build Action to Embedded Resource. The File Name is "Security.ico"
Here is my form level code that uses your nice class. Dim Res As New CResource
Dim myIconS As Icon
myIconS = Res.GetIcon("Security")
Me.Icon = myIconS "Dennis" <De****@discussions.microsoft.com> wrote in message news:E5**********************************@microsof t.com... Try this class to retrieve embedded resources. Note that the names of the files are CASE sensitive including the .ico or .bmp endings.
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 -- Dennis in Houston
"Lou" wrote:
This method does not seem to work or I can't get it to work?
I added an icon file to my project I set it to "embedded resource" and added the code below in the proper format but it returns null. There doesn't seem to be anything else to look for?
There must be something missing?
-Lou
"AMercer" <AM*****@discussions.microsoft.com> wrote in message news:6E**********************************@microsof t.com... >> 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 > > The easiest thing to do is as follows. > > 1. Add the .ico file(s) to your project. > 2. For each icon file, set the build action to "embedded resource". > This > will include the .ico file in your .exe file (my direct experience is > only > with windows form .exe files, but I expect this will work with other > app > types). > 3. In your program, you can get an icon object via the code fragment > shown > below. If the name of the icon file xxx.ico, and the name of your app > is > yyy, then the name of the icon resource in your .exe file is > "yyy.xxx.ico". > > dim s as string = "yyy.xxx.ico" ' your names replace yyy and xxx > dim MyIcon = New > Icon(System.Reflection.Assembly.GetExecutingAssemb ly.GetManifestResourceStream(s)) > > Now you can set a form's icon like: someform.Icon=MyIcon. > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ed Isenberg |
last post by:
I notice that a lot of Web pages have an icon that is displayed preceding
the URL in the place in the browser where the URL is displayed. When I
bookmark or add this to Favorites the icon is also...
|
by: Alexander Keßler |
last post by:
Hi,
I asked u this morning:
---------------------------------------
I want to programm some kind of Explorer like the Windows Explorer.
And I want to know how can i get the same Icons/Symbols...
|
by: Dickyb |
last post by:
Extracting an Icon and Placing It On The Desktop (C# Language)
I constructed a suite of programs in C++ several years ago that handle my
financial portfolio, and now I have converted them to...
|
by: IcingDeath via DotNetMonster.com |
last post by:
I am building this SQL Server database app in which i can store files. In
order to display files I want to have the app show the associated icon for
the extension of the file that is in the...
|
by: Dennis |
last post by:
I have about 50 images in my application as "embedded resources". They are
Icon size (16x16 and 24x24 and 32x32). I can use either the bitmap version
or convert them to Icons. Either way seems...
|
by: SveinErik |
last post by:
Hi, I'm trying to find a method to save bmp, jpg and png files as ico
files, 16x16 size. I have managed to convert and save bmp files to
icon, but only in 32x32 size. I can't figure out how to save...
|
by: laredotornado |
last post by:
Hi,
When I save out an HTML file to my desktop (I'm using Windows XP), it
saves with the Firefox icon, presumably because I have Firefox as the
default application to open my HTML files. Is it...
|
by: Christian Blackburn |
last post by:
Hi Gang,
I have come across something that I wouldn't believe unless I'd seen
it with my own eyes, a DOS program with an icon. Can someone tell me
how to change the icon, my company no longer...
|
by: Anne |
last post by:
Hi,
Is it possible to change the startup-icon of a .mde-file? I know I can
change it in a shortcutfile, but I want it also be changed in the .mde-file.
Thanks in advance
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |