[thelist] question concerning c# dynamically changingwhatisinapicturebox
Chris Marsh
thelist at cjmarsh.com
Tue Aug 15 20:05:26 CDT 2006
Lasuras
> This is a practice piece. I've got an eleven floor elevator
> (0-10), and an
> image for each floor. This routine tests to see if the floor
> has an elevator
> car on it. If it does, it inserts a picture of an elevator.
> If it doesn't,
> it uses a picture of elevator cables. I am doing this as part of a
> portfolio, so I want it to LOOK cute, too!
Your method CloseDoor() in the file Form1.cs needs changing. One solution is
as follows (see code). Caveat: the variable imagePath requires a valid path
to a file, otherwise an exception will be thrown on the following line.
private void CloseDoor()
{
for (I = 0; i < 10; i++)
{
string imgPath = myElevator.CloseElevatorDoor(i).ToString();
Bitmap bgImage = new Bitmap(imgPath);
pbxFloor0.BackgroundImage = bgImage;
}
}
You could contract this to a single line as follows, but I've left it as
three lines in the interests of clarity.
pbxFloor0.BackgroundImage = new
Bitmap(myElevator.CloseElevatorDoor(i).ToString());
Let me know if this solves your problem!
HTH
--
Regards
Chris Marsh
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.10.10/419 - Release Date: 15/08/2006
More information about the thelist
mailing list