ShowDialog should only be used when business requirements indicate that that form when open is the only form that can be used. Seems you should use Show and have methods to disable controls and enable controls.
The following, placed in a public static class provide disable controls on a form with a param parameter for excluding controls from being disabled. This may or may not be suitable for what you want but perhaps if not the code can be helpful for other task.
/// <summary>
/// Disable all controls on a form
/// </summary>
/// <param name="parentControl">Form to work with</param>
/// <param name="exclude">list of controls to exclude</param>
public static void DisableControls(this Control parentControl, params string[] exclude)
{
var controls = parentControl.Descendants<Control>().ToList();
if (exclude.Any())
{
foreach (var control in controls.Where(control => !exclude.Contains(control.Name)))
{
control.Enabled = false;
}
}
else
{
foreach (var control in controls)
{
control.Enabled = false;
}
}
}
/// <summary>
/// Enable all controls on a form
/// </summary>
/// <param name="parentControl"></param>
public static void EnableControls(this Control parentControl)
{
parentControl.Descendants<Control>().ToList().ForEach(c => c.Enabled = true);
}
/// <summary>
/// Base method for obtaining controls on a form or within a container like a panel or group box
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="control"></param>
/// <returns></returns>
public static IEnumerable<T> Descendants<T>(this Control control) where T : class
{
foreach (Control child in control.Controls)
{
if (child is T thisControl)
{
yield return (T)thisControl;
}
if (child.HasChildren)
{
foreach (T descendant in Descendants<T>(child))
{
yield return descendant;
}
}
}
}
Example
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
this.DisableControls("button1", "button3", "button4");
}
private void button4_Click(object sender, EventArgs e)
{
this.EnableControls();
}
}