On a Windows Form, I’m trying to use PictureBoxes as status icons. I have 4 icons for Running, Stopped, StartPending and StopPending. I wasn’t sure how best to do this, so I decided to just stack them on each other and make only the one that’s valid visible. I came up with something like this.
switch (currentServiceStatus)
{
case "Running":
pb_startedTestService.Visible = true;
pb_startingTestService.Visible = false;
pb_stoppedTestService.Visible = false;
pb_stoppingTestService.Visible = false;
break;
case "StartPending":
pb_startedTestService.Visible = false;
pb_startingTestService.Visible = true;
pb_stoppedTestService.Visible = false;
pb_stoppingTestService.Visible = false;
break;
case "Stopped":
pb_startedTestService.Visible = false;
pb_startingTestService.Visible = false;
pb_stoppedTestService.Visible = true;
pb_stoppingTestService.Visible = false;
break;
case "StopPending":
pb_startedTestService.Visible = false;
pb_startingTestService.Visible = false;
pb_stoppedTestService.Visible = false;
pb_stoppingTestService.Visible = true;
break;
}
Which I’m okay with if it was just one service, but there are at least 7 services I’m going to be checking and think that’s a little much for a little icon next to the service name. Am I being obsessive? Is it not that big of a deal and won’t make my code as sloppy as I think it will? Is there an easier or better way to do this?
Why not use one PictureBox and in your switch statement simply change out which image is being displayed. IE: PictureBox1.Image = …
And assuming you have the pictures loaded into your resources, here is the syntax for accessing them.