Solved

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

Posted on 2009-06-29
3
701 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
3 Comments
 
LVL 12

Accepted Solution

by:
wht1986 earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now