DragonNightz wrote:
I am thinking that an array would work to load the menu items into that then check them to see if they have been checked and run it that way.
Good idea.
Here's an example with loops for you:
private List<ToolStripMenuItem> allFreqItems;
private List<ToolStripMenuItem> allDurItems;
allFreqItems = new List<ToolStripMenuItem>();
allFreqItems.Add(cms1MinFreq);
allFreqItems.Add(cms2MinFreq);
allFreqItems.Add(cms5MinFreq);
allFreqItems.Add(cms10MinFreq);
allDurItems = new List<ToolStripMenuItem>();
allDurItems.Add(cms10MinDur);
allDurItems.Add(cms20MinDur);
allDurItems.Add(cms30MinDur);
allDurItems.Add(cms1HourDur);
bool freqOK = false;
bool durOK = false;
foreach(ToolStripMenuItem item in allFreqItems)
{
if (item.Checked)
{
freqOK = true;
break;
}
}
foreach(ToolStripMenuItem item in allDurItems)
{
if (item.Checked)
{
durOK = true;
break;
}
}
if (freqOK && durOK)
{
tmrMain.Start();
btnStart.BackColor = Color.Red;
btnStart.Text = "Started";
}
else
{
MsgBox("Please select Frequency and Duration by right clicking the window.");
}
with .Net 3.5 and the
Any
extension method you don't even need the loops to iterate over the collections:
bool freqOk = allFreqItems.Any(item => item.Checked);
bool durOK = allDurItems.Any(item => item.Checked);
Warning: examples produced in a browser, may contain syntax errors :)