Load vb.net picture box image at compile time

AlwaysSomethingToLearn used Ask the Experts™
I have a picture box on a form and want to load an image at compile time dependent on client. The image is selected using a compiler contstant.

#If CLIENT = "XXXX" Then
        Dim im As Image = Image.FromFile("C:\Dependencies\Logos\ClientLogo.jpg")
        Me.pbLogo.Image = im
        Me.pbLogo.Size = New Drawing.Size(175,76)
        Me.pbLogo.Location = New System.Drawing.Point(37,30)
#ElseIf CLIENT........................

The problem is that this code, when compiled and deployed, expects the file C:\Dependencies\Logos\ClientLogo.jpg to exist on the target system. How can I use early binding (such as when I right click on the picture box and select choose image) to import the image at compile time?

I am using Visual Studio 2005
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I guess I am curious. Why wouldn't you just use an image file for the client and a settings file that tells the name of the image file if need be, then when the form loads, find the file if it exists and load it?
Because the application is installed on multiple client systems for multiple customers. It would mean one of my programmers remembering to package the correct image file with the deployment files. I've already had instances where customer A has installed the application and seen customer B's logo.

The idea was to have all customer configuration automatically performed at compile time by changing a single customer code in the custom compile constants.
OK. How about this.
If you make a new form in vb.net.   Add a picture box, then add an image to that. Then in your Solution Explorer, click the icon to show all files (right beside the refresh icon).  When they are showing, you will see something like Form1.resx. Open that, in the top left change to "Images".
Inside there you will see a resource named PictureBox1.Image.  

Now in solution explorer open the Form1.Designer.vb, you will see something like:
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)

That's how it is loading it.  That being said, what if you made the picture box with no image in it. Went into your ".resx" file and added a bunch of images, each being named by the clientID.  
Then when the form loads in the Load event, do something like

#Const ClientID = 3

#if ClientID=3 then
#elseif ClientID=4 then
#end if

So all you'd need to do is change the #Const ClientID to whatever ID, or perhaps you could define it in My Project.

Wouldn't this work?  If you don't have too many clients it shouldn't matter that all of the logos are actually in the resource file and you pick the right one.  If you have 1000's this won't be the best choice for sure.

Interesting idea, it should work (about 15 clients only right now for this solution). I actually found another work around. I added multiple picture boxes to the form, each with it's own image, set them all to visible = false during the load event and then turned on the one that corresponded to the client code.

Many thanks for your idea, I'll certainly try it. I've closes the thread and assigned you the points.
One more thing.. I don't know if the .resx gets monkeyed with by the designer such that it would get rid of your resources (though I think if you name them things like 3.image and not PictureBox1.image, you'd be safe), so you might want to go into "My Project" and do resources there if that is the case.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial