|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Accessing embedded resourcesI've created a custom button which I can stick into my toolbox. This all works well and I see my button in the designer. This button uses customised graphics and I want to stick it in the dll as an embedded resource. In the project tree I added a folder in which I stick the bitmaps (png's actually) and set he compile option for them to EmbeddedResource. But how do I access them from my (vb)source? The docs say: new bitmap(type, resourcename) but what is the resourcename? Where do I find that? I've tried just entering the filename, but that gives me an error saying it can't be located in the namespace of my custom button. -- Rinze van Huizen C-Services Holland b.v The resource name is <namespace.name>
For example, if you have a bitmap, bar.bmp embedded in a project with a namespace of foo. Then the resource name is foo.bar.bmp NOTES: The resource name is case sensitive It is the namespace that is important not the project name - by default they are the same but may not be I have seen the new bitmap(type, resourcename) version before and cannot promise that it will work. I generally use Dim bmp As New System.Drawing.Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream _ (<resourcename>)) hth, Alan. alanto***@users.com wrote:
Show quoteHide quote > The resource name is <namespace.name> Thank you both, that did the trick. I'm keeping Denis' class for future > > For example, if you have a bitmap, bar.bmp embedded in a project with a > namespace of foo. Then the resource name is foo.bar.bmp > > NOTES: The resource name is case sensitive > It is the namespace that is important not the project name > - by default they are the same but may not be > > I have seen the > > new bitmap(type, resourcename) > > version before and cannot promise that it will work. > > I generally use > > Dim bmp As New > System.Drawing.Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(<resourcename>)) reference since it was a bit overkill for this particular instance. -- Rinze van Huizen C-Services Holland b.v Here's a class that I use to retrieve different types of resources (note that
the resource names are case sensitive including any .extension, i.e., .ICO is different from .ico). 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 -- Show quoteHide quoteDennis in Houston "C-Services Holland b.v." wrote: > Hi all, > > I've created a custom button which I can stick into my toolbox. This all > works well and I see my button in the designer. This button uses > customised graphics and I want to stick it in the dll as an embedded > resource. In the project tree I added a folder in which I stick the > bitmaps (png's actually) and set he compile option for them to > EmbeddedResource. But how do I access them from my (vb)source? > > The docs say: > > new bitmap(type, resourcename) > > but what is the resourcename? Where do I find that? I've tried just > entering the filename, but that gives me an error saying it can't be > located in the namespace of my custom button. > -- > Rinze van Huizen > C-Services Holland b.v >
Are people using data binding now?
Strongly Typed Key Value Collections within a For Next loop Upgrading VB2003 to 2005 how to do Binding with code Problem adding new row in Access Table what to do, what to do [URGENT] Images and Thumbnail : pb with rendering quality How to embed the excel worksheet into my forms? Setup Project Web Windows authentication login |
|||||||||||||||||||||||