Apparently the ewase of programming has disappeared when I stopped using python.

btnPlay.BackgroundImage = Image.FromFile("\\Images\\playbtn_down.jpg");

Now I have the image in a Images folder...and I don't see why this doesn't work (from build [F5])....
this is making me very bitter......It's one of the many problems I've encountered since I started using this language (all unsolved). BTW...I'm using MS Visual C# 2005 Express for what its worth....guh

Sorry you are having problems adapting to a new language. I find c# one of the easier ones to learn.

Your file spec is looking for current dir\images\playbtn_down.jpg
But just what is the current directory ? Is in on the C drive ? D ?

You really can't tell from this file path specification. When using paths, you should never assume that your application environment is sitting on the same directory or even drive that it started. IOW, do not use relative paths. Retry your example using the fully qualified path: example: "C:\\Images\\Playbtn_down.jpg".

--Jerry

One more thing.... If you must use a relative path, preface it with Application.StartupPath

-- Jerry

Oh ok. But I was just thinking, if I were to give the program to a couple friends it might not work since they might store the program seperately....

Thank you, I'll get to it right away

Since you want to have an image on the button, why not assign it in the IDE ?

If you are using something other than the VS IDE, and that IDE that does not allow you to assign the image, then you can place the image into the resource section, and load it from there on startup.

This way, you do not rely on a image file being in a specific place. It also reduces the number of files you need to supply with your product, and guarantees that the image will be available at runtime.

--Jerry

Well im using VS IDE, but i want to the image to change back and forth when the mouse enters and leaves the button's space.

I have not learned how to use resource files. Is there a tutorial for this?

Anyway, i've gotten it to work using the full path as you said, and those other problems seem to be disappearing one by one (i've learned to configure my splash properly and how to show/hide my forms properly...well i think).

One more question though, i'm using vcsharp express 2005. Now that I've gotten it working using full-paths, does the compiler have an option or something to put all my external stuff into a resource file (or something similar) upon compiling? (make it easier for me without having to bother my head about how to use resource files...)

Thanks though...it's actually going smoother now...

I am not familiar with the Express version IDE. But if you can see the Resources item under your project in the Solution Explorer, then you should be able to add any kind of resource that you want. Whatever resides in the resources item, is compiled into your program.

Look in your InitializeComponent() method, and you will see how
System.ComponentModel.ComponentResourceManager is used to pull resources out of the reources section of your compiled program.

I tell my programmers that there is always at least five ways to do anything. The most efficient code (fastest to execute) and easiest to maintain should be your first pick.

Since you are presently using a file IO process to exchange the button image, may I propose a faster method ?

Since you are not yet familiar with resources I won't go into that technique. What you can do is let the compiler do some of the work for you. Add two buttons, give button1 the normal image (what you display when the cursor is not in your real button canvas area), and button2 with the image of when the cursor is in the canvas area. Make both buttons invisble. When the user enters or leaves your real button, you can assign the correct image from one of these hidden buttons instead of going to the Disk. The idea is to reduce the file IO of reading a file from disk (the slowest operation for a PC).

That method will be very fast, no external image files, and the images for your hidden buttons were loaded only once within your InitializeComponent method. They are already in memory when you need their images.

If I were doing the project, I would have an imagelist assigned with my images, and just assign the correct indexed image to the button when needed.

Have fun.. and please review the InitializeComponent method in your code.

--Jerry
method.

Hey I did what you said and I learnt how to use the resources. I like how my images are now globally available, and don't have to use filenames which can lead to problems.

Thanks...and I'm beginning to really like this language after all...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.