Loading Bitmaps into Pictureboxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a little problem with getting images into my pictureboxes while the
programm is running. I want to have the option changing pictures without
recompiling the programm. Because of this I tried to load pictures and then
put them into a picturebox with the folloing code I found here in the
newsgroup:

Dim imageName As New String("Test.bmp")

Dim Pippo = New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MedicAlertClient.images." + imageName))

picTest.Image = Pippo

But I get a SystemNullReference Exeption. Can somebody tell my how to find
out where my base directory is, and how to load an assign an image to the
picturebox?

Thx,
Cyberdot

PS: Excuse my bad english, it's not my native language... ;o)
 
GetManifestResourceStream is used to retrieve embedded resources within your
exe/dll, if you want to load an image file in the same folder, then you can
simply pass the full file path into the Bitmap constructor. You can use the
technique here to determine your applications path at runtime, and append
the bitmap filename to this path:-
http://wiki.opennetcf.org/ow.asp?CompactFrameworkFAQ/StartupDirectory

'add these to the top of your code file
Imports System.IO
Imports System.Reflection


' This is the full directory and exe name
Dim fullAppName As String =
[Assembly].GetExecutingAssembly().GetName().CodeBase

' This strips off the exe name
Dim fullAppPath As String = Path.GetDirectoryName(fullAppName)

' This adds a file name to the path
Dim fullFileName As String = Path.Combine(fullAppPath, "Test.bmp")

Dim Pippo = New Bitmap(fullFileName)

picTest.Image = Pippo

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Back
Top