I always try to think about how to improve my code or other people's code. One thing I notice is some people using two methods for enable and disable controls/buttons. Wouldn't it be much better to just have one method? This would mean less code and only one location to update the code.
Here is the old way:
private void EnableControls()
{
lvMovieList.Visible = true;
btnSearch.Enabled = true;
btnRescan.Enabled = true;
txtSearch.Enabled = true;
btnTV.Enabled = true;
pnlAdvancedSearch.Enabled = true;
tcFindMovies.Enabled = true;
}
private void DisableControls()
{
lvMovieList.Visible = false;
btnSearch.Enabled = false;
btnRescan.Enabled = false;
txtSearch.Enabled = false;
btnTV.Enabled = false;
pnlAdvancedSearch.Enabled = false;
tcFindMovies.Enabled = false;
}
Here is the better improved way:
private void ChangeControls(bool
onOff)
{
lvMovieList.Visible = onOff;
btnSearch.Enabled = onOff;
btnRescan.Enabled = onOff;
txtSearch.Enabled = onOff;
btnTV.Enabled = onOff;
pnlAdvancedSearch.Enabled = onOff;
tcFindMovies.Enabled = onOff;
}
So now when you want to disable controls you pass in false and pass in true when you want to enable the controls.
E.G:
ChangeControls(true);
If you need one control set to true when disabling all other controls.
Then you can do this:
btnCancel.Enabled = onOff ? false : true;
I know this is pretty basic stuff but im sure some people out there will gain from reading it.
5f22a1b2-29ba-4f33-bac8-6cb19d8d44c6|8|3.8