I have created a Windows Form application in C#. I designed interfaces with picture boxes and background pictures. But i need add pictures after it hard coded, I don’t know how to customize those interfaces. (Basically the Theme), background images and picture box images.
I have created a Windows Form application in C#. I designed interfaces with picture
Share
When do you want to do this changes? Hopefully you can add some event handler that allows you to add code that will execute when you want to do this modifications.
As for how to do the changes. You will need the name of the member variable of the components.
Say, you have a
PictureBoxthat goes by the namePicMyPicture. Then you can do this:or
or similar for other properties and components.
Please look at your IDE, chances are that it allows you to define the event handler. For intance you can find events of the components in the properties window of Visual Studio (are you using Visual Studio?), or similar locations in other IDEs.
Ok, but the above has a problem… from where do you get that image?
Well, it may come loaded from a file, from a resource in your application, downloaded from Internet, recovered from a database, or even generated at runtime.
The more commons for your case are resources and files, so I’ll cover those.
This codes loads an image from disk:
You may be wondering… how can will I write the path if I don’t know where the final user will put application? well, to load a file from a relative path to the working directory of your application, you can do this:
This codes loads an image from the resources in your application:
You have to make sure that you have added the resource to your project before hand. Check out the documentation on your IDE to find out how.