Reputation: 23
Context: I am creating mock-ups for a web based application. I use WinForms Application to do this. In the future I will use WebForms but this question applies to both I'm sure.
Question: I have panels that are transparent which I place over a webpage-sized picturebox. The panels act as clickable "links" to "navigate" to "pages".
In actuality when a panel is clicked the picturebox (which serves as the background) changes to a screen capture of a different webpage giving the appearance of web navigation. The panels act as masks on things users click on to navigate.
I would like to add these existing panels into a list for the purpose of changing them. For example, I would like to change their .Enabled attribute set to false; in one statement.
I currently accomplish this by doing this:
public void TurnOffPanels()
{
aPnl.Enabled = false;
bPnl.Enabled = false;
cPnl.Enabled = false;
dPnl.Enabled = false;
ePnl.Enabled = false;
fPnl.Enabled = false;
{
My question is: how can code this using a list of my panels?
PS: This is my first question here so please feel free to berate me for format, noobness...whateves
Upvotes: 2
Views: 3203
Reputation: 5103
Oof, well, I wouldn't use winforms applications for mockups. There's plenty of cheap mockup applications like balsamiq and the like to do that, or gimp if you want to provide a visual aid.
However, I think you're meaning to say that you're developing "prototypes" in winforms. Prototypes allow people to interact while mockups are just flat images.
Anyway, if you want to hide a list of panels, you can just create a field in your codebehind of the panels you want to flicker, and just operate on that.
iE:
public class Form {
List<Panel> myPanels = new List<Panel>();
public Form() {
myPanels.Add(aPnl);
myPanels.Add(bPnl);
//etc
}
public TurnOffPanels(){
foreach(var panel in myPanels){
panel.Enabled = false;
}
}
}
Edit: Also your question is formatted fine, and you gave plenty of detail. As far as first questions go, good job!
Upvotes: 2
Reputation: 389
If the panel are Childrens of the same form, then:
foreach(Panel p in this.Controls)
p.Enabled = false;
Upvotes: 0