I have a Windows Form with A LOT of controls separated into groups based on the day (Monday, Tuesday, etc.), and functions dependent on the controls within that day. I want to find a better way to structure my code, because right now it feels and looks like spaghetti.
Currently, my code is technically working, but it's a mess. It's way too long, and when I need to edit some of my functions I'm having to edit them for 7 different days and find/replace control names and stuff.
With the help of a more experienced colleague who suggested using parameters (duh), I've found a way to simplify it some. I haven't applied it to my main code yet, but have played around with it in a simpler test environment.
The problem now is that I have an absurd number of parameters that I'm hoping can be grouped somehow.
I've looked into the GroupBox control, but it doesn't seem to do what I hoped.
Here's a simplified example of code that I'm working with. In my actual code, there are a lot more controls involved, and therefore a lot more parameters.
private void validate(DateTimePicker start, DateTimePicker end, DateTimePicker lunch, Label day)
{
if ((lunch.Value < start.Value || lunch.Value >= end.Value))
{
day.Visible = true;
}
if ((lunch.Value >= start.Value && lunch.Value < end.Value))
{
day.Visible = false;
}
}
I have a feeling I should be using an array to group these? Can anyone confirm? Thanks.
TL;DR: How can you group a lot of parameters for passing to a function?