Solved

New Bitmap (Filename as String)  - Why is this not a string?

Posted on 2009-06-29
3
707 Views
Last Modified: 2012-08-14
I'm writing my first shared com add-in for excel in VB.Net and my experience is primarily with VBA so I'm learning.   The add-in adds a ribbon, the ribbon has a bunch of custom png images used for button images.  

Why does Return New Bitmap(My.Resources.AcctgUline16) return a bitmap

and

Dim sImage as String = "My.Resources." & control.id & "16"
Return  New Bitmap(sImage)

does not?

From VS 2008 the Intellisense says Bitmap(filename as string)
Working Code:
   Public Function GetImage(ByVal control As Office.IRibbonControl) As Bitmap
        'control.id = AcctgUline
        Return New Bitmap(My.Resources.AcctgUline16)
    End Function
 
 
Does not work:
    Public Function GetImage(ByVal control As Office.IRibbonControl) As Bitmap
        'control.id = AcctgUline
        Dim sImage As String = "My.Resources." & control.Id & "16"
        'sImage = My.Resources.AcctgUline16
        Return New Bitmap(sImage)
    End Function

Open in new window

0
Comment
Question by:slindberg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
wht1986 earned 50 total points
ID: 24741135
Bitmap has an overloaded constructor, one of which accepts a parameter of a bitmap and another a string to a file on the filesystem

when you use My.Resources.AcctgUline16, you are actually supplying a bitmap

using the string  "My.Resources." & control.id & "16"
the code is attempting to find a file named "My.Resources.AcctgUline16" on the file system
0
 
LVL 39

Expert Comment

by:abel
ID: 24741140
For 50p? Must be easy....

Microsoft Intellisense also says "Image original", which is your first line. The second example, with sImage does not because you do not give the path to the image. Instead, you give a string representing a line in your code, which doesn't mean anything to the constructor. Give it a path, like Bitmap("c:/temp/myimage.jpg") for instance.
0
 

Author Comment

by:slindberg
ID: 24741204
After your post and finding the post below I modified my code and it works.  Thanks

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21774267.html?sfQueryTermInfo=1+resourc+variabl+vb.net#a16192685

    Public Function GetImage(ByVal control As Office.IRibbonControl) As Bitmap
        Dim resMan As New ResourceManager("mpmRibbons.Resources", Me.GetType.Assembly)
        Dim sImage As String = control.Id & "16"
 
        Return New Bitmap(CType(resMan.GetObject(sImage), System.Drawing.Image))
 
    End Function

Open in new window

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# class library debugging - Breakpoint will not hit. 8 43
Amazon S3 Images with .Net 3 62
How to repeat the data 4 42
how to check mis-spellings in a select SQL 2 51
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question