473,387 Members | 1,863 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,387 software developers and data experts.

Icon & embedded resource

I've created a c# dll with some classes and i've included some icons that i
can see with ILDASM like namespace.iconfile.ico

I re-use this dll (dll reference) and relative classes in many vb project

How i can re-use icons?
Nov 21 '05 #1
2 1576
Assuming MyForm is a form object, I set its icon like this:
Dim sra As Reflection.Assembly =
Reflection.Assembly.GetExecutingAssembly
Dim str As IO.Stream = sra.GetManifestResourceStream("xxx.yyy.ico")
MyForm.Icon = New Drawing.Icon(str)
The documentation hints at using an embedded resource directly. I could not
figure out how to do it for both .wav and .ico resources, so I use an IO
stream for both. The code fragment above is two years old, and there may be
a better way at this time.

"Pippo" wrote:
I've created a c# dll with some classes and i've included some icons that i
can see with ILDASM like namespace.iconfile.ico

I re-use this dll (dll reference) and relative classes in many vb project

How i can re-use icons?

Nov 21 '05 #2
Here is a class I wrote to retrieve embedded resources:

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
"Pippo" wrote:
I've created a c# dll with some classes and i've included some icons that i
can see with ILDASM like namespace.iconfile.ico

I re-use this dll (dll reference) and relative classes in many vb project

How i can re-use icons?

Nov 21 '05 #3

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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.