The obvious "easy win" in refactoring here would be to add Controls whose visibility is to be set to the same value to the ControlCollection of Panels, and to, then, simply make the Panel that contains them Visible or Hidden. You can make those Panels have no border, and have the same background color as whatever they are displayed "on," if that's a concern.
To get into more substantial refactoring really requires understanding the different UI states (modes, if you will) that your Application uses.
There are a number of data structures that could be used to handle automating what Controls are visible each time the UI changes from one mode to another. I might prototype using something like a Dictionary<Enum,List<Control>> to map UI states to the list of Controls which should be visible in each state:
// rough sketch for educational purposes only: will compile as is, and produce expected output, but should be regarded as only a proof-of-concept exercise:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace StateChangeTest
{
[Flags]
public enum StateVisibility
{
State1 = 0x01,
State2 = 0x02,
State3 = 0x04,
State4 = 0x08
}
public class StateMap
{
public Dictionary<StateVisibility,List<Control>> dctVisibleByState = new Dictionary<StateVisibility, List<Control>>();
public StateMap()
{
dctVisibleByState.Add(StateVisibility.State1,
new List<Control>
{
new Button {Text = "button1"},
new RadioButton {Text = "radioButton1"}
});
dctVisibleByState.Add(StateVisibility.State3,
new List<Control>
{
new Button {Text = "button2"},
new RadioButton {Text = "radioButton2"}
});
dctVisibleByState.Add(StateVisibility.State4,
new List<Control>
{
new Button {Text = "button3"},
new RadioButton {Text = "radioButton2"}
});
}
}
}
private void testStateMap()
{
StateMap sMap = new StateMap();
StateVisibility sv12 = StateVisibility.State3 | StateVisibility.State4;
foreach (StateVisibility sv in sMap.dctVisibleByState.Keys)
{
bool isVisibleInState = sv12.HasFlag(sv);
sMap.dctVisibleByState[sv].ForEach(cntrl => cntrl.Visible = isVisibleInState);
}
foreach (StateVisibility sv in sMap.dctVisibleByState.Keys)
{
Console.WriteLine(sv.ToString());
foreach (Control cntrl in sMap.dctVisibleByState[sv])
{
Console.WriteLine("Control: {0} Visible: {1}", cntrl.Text, cntrl.Visible);
}
Console.WriteLine();
}
}
State1
Control: button1 Visible: False
Control: radioButton1 Visible: False
State3
Control: button2 Visible: True
Control: radioButton2 Visible: True
State4
Control: button3 Visible: True
Control: radioButton2 Visible: True
Note that a quick sorting of your conditions (in NotePad++) in the two cases shown shows that with the exception of 'lblEditRow3a all other Controls have identical assignments, and there are repeated assignments. Every one of the Panels in the two case statements is set to 'Visible = false. So you can clean your code up quite a bit:
COICasePanel.Visible = false;
COICasePanel.Visible = false;
assurancePanel.Visible = false;
assurancePanel.Visible = false;
environmentPanel.Visible = false;
environmentPanel.Visible = false;
euthPanel.Visible = false;
euthPanel.Visible =false;
fundingPanel.Visible = false;
fundingPanel.Visible = false;
housingPanel.Visible = false;
housingPanel.Visible = false;
justificationPanel.Visible = false;
justificationPanel.Visible = false;
lblEditRow2.Visible = false;
lblEditRow2.Visible = false;
lblEditRow3.Visible = false;
lblEditRow3.Visible = false;
lblEditRow3.Visible = true;
lblEditRow3.Visible = true;
lblEditRow3a.Visible = false;
lblEditRow3a.Visible = true;
lblEditRow4.Visible = false;
lblEditRow4.Visible = false;
lblEditRow6.Visible = false;
lblEditRow6.Visible = false;
lblEditRow6a.Visible = false;
lblEditRow6a.Visible = false;
manPanel.Visible = false;
manPanel.Visible = false;
radEditRow4a.Visible = false;
radEditRow4a.Visible = false;
rblAnimalManipulation.Visible = false;
rblAnimalManipulation.Visible = false;
rblChanged.Visible = true;
rblChanged.Visible = true;
rblChanged.Visible = true;
rblEuthanized.Visible = false ;
rblEuthanized.Visible = false;
sopPanel.Visible = false;
sopPanel.Visible = false;
speciesPanel.Visible = false;
speciesPanel.Visible = false;
txtEditOLDASAF_Number.Visible = false;
txtEditOLDASAF_Number.Visible = false;
txtEditSectionsAmended.Visible = false;
txtEditSectionsAmended.Visible = false;