Wednesday, January 30, 2013 1:02 PM
Is there a way of adding background images to buttons in a panel but where the image source is a string stored on my SQL backend?
For Each ctrl As Control In Form1.panApps.Controls If TypeOf ctrl Is Button Then Form1.Controls("Button" & GlobalVariables.AppNum).BackgroundImage = Image.FromFile(Form1.DataSet.DataTable.Rows(GlobalVariables.AppNum).Item(6)) End If Next
this is the above code i use but for some reason it wont recognise the fromfile(...) part as a line of text even though when i query the dataset in the same way in the immedate window it comes through perfectly.
The loop isnt finished yet but i just cant seem to get my head round this button image problem which throws many spanners in the works.
Any help would be appreciated.
Wednesday, January 30, 2013 2:12 PM
What is the string that is stored in your SQL backend? Is it a file name? Or is it some kind of Base-64 encoded version of the image file's contents? What format is the image in?
If there is a file name stored in the database, then your client will need to be able to resolve the path to the file. Depending on your application this may mean that the file name is a URL, or a UNC path accessible from your local network. It may also be that the file name simply refers to an image that is on the client machine, perhaps as part of the client software install.
If the actual raw data is stored in your database, then you need to decode it to a binary format first. (Like with a base-64 decode, or whatever.) Then you need to supply a stream that accesses the decoded data, and use Image.FromFile and pass the stream in as a parameter.