patterncsharpMinor
Showing/hiding controls based on event
Viewed 0 times
showingcontrolshidingbasedevent
Problem
I have the following code in a portion of my program that hides/shows certain elements based on the status of a certain checkbox:
Is there a better way to handle this without a whole bunch of conditionals that set other controls to hide/show?
private void enableFolderVariableRemoval_CheckedChanged(object sender, EventArgs e)
{
if (enableFolderVariableRemoval.Checked)
{
cleanFolderTextPanel.Visible = true;
cleanTextPanel.Visible = true;
}
else
{
cleanFolderTextPanel.Visible = false;
if (cleanFilenameTextPanel.Visible == false)
{
cleanTextPanel.Visible = false;
}
}
}Is there a better way to handle this without a whole bunch of conditionals that set other controls to hide/show?
Solution
Not sure if there are any other constraints but here is one possible solution:
private void enableFolderVariableRemoval_CheckedChanged(object sender, EventArgs e)
{
cleanFolderTextPanel.Visible = enableFolderVariableRemoval.Checked;
cleanTextPanel.Visible = cleanFolderTextPanel.Visible || cleanFilenameTextPanel.Visible;
}Code Snippets
private void enableFolderVariableRemoval_CheckedChanged(object sender, EventArgs e)
{
cleanFolderTextPanel.Visible = enableFolderVariableRemoval.Checked;
cleanTextPanel.Visible = cleanFolderTextPanel.Visible || cleanFilenameTextPanel.Visible;
}Context
StackExchange Code Review Q#15168, answer score: 6
Revisions (0)
No revisions yet.