NekoManu Posted September 23, 2004 Posted September 23, 2004 I'm trying to set/change teh background image of a form at runtime. I found this code, but I always get the error: "Invalid parameter used". dlgStartUp.BackgroundImage = new Bitmap("dictionary.jpg"); Can someone tell me how to get a jpg on the form please? Quote
Leaders Iceplug Posted September 23, 2004 Leaders Posted September 23, 2004 Does it work if you use a bmp instead? It could be a problem with the JPG. Have you tried other JPGs? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
NekoManu Posted September 23, 2004 Author Posted September 23, 2004 No it does not work with a bmp. Quote
Administrators PlausiblyDamp Posted September 23, 2004 Administrators Posted September 23, 2004 Where is the image located? Have you tried specifying a full path to the file? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* DiverDan Posted September 24, 2004 *Experts* Posted September 24, 2004 Maybe you could try this: Put the .jpg bitmap file in the Bin directory of your project then call the bitmap with: dlgStartUp.BackgroundImage = Image.FromFile(Application.StartupPath & "\dictionary.jpg") or if dlgStartUp is a form then Me.BackgroundImage = Image.FromFile(Application.StartupPath & "\dictionary.jpg") Then remember to include the .jpg file in the project's distributation package. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
NekoManu Posted September 26, 2004 Author Posted September 26, 2004 The image is in the resource. Quote
Administrators PlausiblyDamp Posted September 26, 2004 Administrators Posted September 26, 2004 Do you mean the image is included as an embedded resource within the executable? If so then clicky Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
NekoManu Posted September 26, 2004 Author Posted September 26, 2004 This is what I tried: this.BackgroundImage = new Bitmap(GetType().Assembly.GetManifestResourceStream("Thai_Dictionary.dictionary.jpg")); Where "Thai_Dictionary" = the name of the namespace/project/solution And "dictionary.jpg" = the name of the image I alsways get the following: 'null' is not a valid value for 'stream'. Quote
Administrators PlausiblyDamp Posted September 26, 2004 Administrators Posted September 26, 2004 Is the .jpeg in a sub-folder of your project? If so C# requires you to use Namespace.FolderName.ResourceName - I've just updated the earlier link to include both a VB and a C# version. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
NekoManu Posted September 26, 2004 Author Posted September 26, 2004 (edited) I tried your C# example and that works. When I try my project it does NOT work. I tried it with space, underscore, .... nothing works. My image is just under the namespace. I included the project, so if you like you can have a look. I must warn you the thing is full of test and most of them don't work.ThaiDictionary.zip Edited September 26, 2004 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted September 26, 2004 Administrators Posted September 26, 2004 Couldn't build the app as it's missing a few references, however make sure that the build action for the jpeg is set to 'Embedded Resource' in the property window. Also it may be worth mentioning that you are using a beta version of vs.net and as such things may differ from the current release. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
NekoManu Posted September 26, 2004 Author Posted September 26, 2004 Thank you very much! The 'Embedded Resource' was indeed the problem. Quote
NekoManu Posted September 27, 2004 Author Posted September 27, 2004 I tried it in a test program and it worked. Today I put it in my library. This is a different namespace and a different solution. As you can guess this does not work anymore. Any idea's on how to solve this? The thing is that I have a property on soSytem with the name of the image. When I create the StartUp form, I want to load the image and then display it. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.