All you have to do is set the PictureBox.Image property:
if (myPicture.Image != null)
{
myPicture.Image.Dispose();
}
myPicture.Image = Image.FromFile(@"F:\Temp\MyImage.jpg");
The dispose just tidies up after yourself!
You can use any image source you have: it could be a Bitmap you have loaded, or a file as I have shown.
"Is there a way to place that code inside my swicth case. So for example if a select Casino Royale that code will then run along with the info code?"
Yes: just add a line before each
break
:
private void lbxFilms_SelectedIndexChanged(object sender, EventArgs e)
{
if (ta == "Action/Thriller")
{
switch (lbxFilms.SelectedItem.ToString())
{
case "Casino Royale":
lbxInfo.Items.Clear();
lbxInfo.Items.Add("Directed By Martin Campbell");
lbxInfo.Items.Add("Starring Daniel Craig, Eva Green, Mads Mikkelson");
lbxInfo.Items.Add("Run Time 144 Minutes, Special Features: Making Of, Commentary, Deleted Scenes and many more" );
SetPicture(@"F:\Films\Casino Royale.jpg");
break;
case "Die Hard":
lbxInfo.Items.Clear();
lbxInfo.Items.Add("Directed by John McTiernan");
lbxInfo.Items.Add("Starring Bruce Willis, Alan Rickman, Bonnie Bedelia");
lbxInfo.Items.Add("Run Time 131 minutes, Special Features: Making of, Outakes, deleted scenes and many more");
SetPicture(@"F:\Films\Die Hard.jpg");
break;
case "Raiders of the Lost Ark":
lbxInfo.Items.Clear();
lbxInfo.Items.Add("Directed by Steven Speilberg");
lbxInfo.Items.Add("Starring Harrison Ford, Karen Allen, Paul Freeman");
lbxInfo.Items.Add("Run time 115 minutes, Special Features: Making of, StoryBoard Comparison, deleted scenes");
SetPicture(@"F:\Films\Raiders of the Lost Ark.jpg");
break;
default:
SetPicture(@"F:\Films\None.jpg");
break;
}
}
And add the code I gave you as a method:
private void SetPicture(string imagePath)
{
if (myPicture.Image != null)
{
myPicture.Image.Dispose();
}
myPicture.Image = Image.FromFile(imagePath);
}