what I want to do is instead in each method to use the same variables controls over again to make something more generic and easier to use.
for example this method I'm using the success flag and change all the variables to be enabled true or false.
public void SetControlsAfterProcessing(bool success)
{
// Set controls' states after processing (whether it was successful or canceled)
btnVideoFileFolder.Enabled = success;
btnSaveLightnings.Enabled = success;
btnBrowseLightningsFolder.Enabled = success;
checkBoxSaveLogger.Enabled = success;
comboBoxLightnings.Enabled = success;
lightningsSelectionTrackBar.Enabled = success;
imagesSelectionTrackBar.Enabled = success;
// ... set other controls
// Update processing state
IsProcessing = false;
UpdateButtonText();
}
but I'm also looking for something to make that I will be also able to set each variable individual.
for example this will be true:
btnVideoFileFolder.Enabled = true;
and this will be false:
btnSaveLightnings.Enabled = false;
but instead typing all the variables over and over again in each method to do something more general and generic.
using Test;
using System.Threading.Tasks;
using System.Windows.Forms;
using XComponent.SliderBar;
public class ControlsStateManager
{
private readonly Button btnStartProcessing;
private readonly Button btnViewLogger;
private readonly CheckBox checkBoxSaveLogger;
private readonly Button btnVideoFileFolder;
private readonly Button btnSaveLightnings;
private readonly Button btnBrowseLightningsFolder;
private readonly ComboBox comboBoxLightnings;
private readonly MACTrackBar lightningsSelectionTrackBar;
private readonly MACTrackBar imagesSelectionTrackBar;
private readonly CustomProgressBar customProgressBar;
private readonly PictureBox lightningImagePictureBox;
// ... add other controls
// Introduce a processing state variable
public bool IsProcessing { get; private set; } = false;
private readonly ProcessingManager processingManager;
public ControlsStateManager(Button btnStartProcessing,
Button btnViewLogger,
CheckBox checkBoxSaveLogger,
Button btnVideoFileFolder,
Button btnSaveLightnings,
Button btnBrowseLightningsFolder,
ProcessingManager processingManager, ComboBox comboBoxLightnings,
MACTrackBar lightningsSelectionTrackBar,
MACTrackBar imagesSelectionTrackBar,
PictureBox lightningImagePictureBox,
CustomProgressBar customProgressBar)
{
this.btnStartProcessing = btnStartProcessing;
this.btnViewLogger = btnViewLogger;
this.checkBoxSaveLogger = checkBoxSaveLogger;
this.btnVideoFileFolder = btnVideoFileFolder;
this.btnSaveLightnings = btnSaveLightnings;
this.btnBrowseLightningsFolder = btnBrowseLightningsFolder;
this.processingManager = processingManager;
this.comboBoxLightnings = comboBoxLightnings;
this.lightningsSelectionTrackBar = lightningsSelectionTrackBar;
this.imagesSelectionTrackBar = imagesSelectionTrackBar;
this.lightningImagePictureBox = lightningImagePictureBox;
this.customProgressBar = customProgressBar;
// ... initialize other controls
}
public void InitializeControls(bool loggerFileExists)
{
// Initialize controls' states in the constructor or load event
btnViewLogger.Enabled = loggerFileExists;
// ... initialize other controls
}
public void SetControlsForProcessing()
{
// Set controls' states during processing
btnVideoFileFolder.Enabled = false;
btnSaveLightnings.Enabled = false;
btnBrowseLightningsFolder.Enabled = false;
checkBoxSaveLogger.Enabled = false;
comboBoxLightnings.Enabled = false;
lightningsSelectionTrackBar.Enabled = false;
imagesSelectionTrackBar.Enabled = false;
// ... set other controls
// Update processing state
IsProcessing = true;
UpdateButtonText();
}
public void SetControlsAfterProcessing(bool success)
{
// Set controls' states after processing (whether it was successful or canceled)
btnVideoFileFolder.Enabled = success;
btnSaveLightnings.Enabled = success;
btnBrowseLightningsFolder.Enabled = success;
checkBoxSaveLogger.Enabled = success;
comboBoxLightnings.Enabled = success;
lightningsSelectionTrackBar.Enabled = success;
imagesSelectionTrackBar.Enabled = success;
// ... set other controls
// Update processing state
IsProcessing = false;
UpdateButtonText();
}
// Add other methods as needed
// For example, if you want to add a method to reset all controls, you can do:
public void ResetAllControls()
{
customProgressBar.UpdateProgress(0);
lightningImagePictureBox.Image = null;
// ... reset other controls
}
// Helper method to update button text based on processing state
private void UpdateButtonText()
{
btnStartProcessing.Text = IsProcessing ? "STOP PROCESSING" : "START PROCESSING";
}
}