My problem is simple. I have this new form, and I just code this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Resize += new EventHandler(Form1_Resize);
this.WindowState = FormWindowState.Minimized;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
ShowInTaskbar = false;
}
else if (WindowState == FormWindowState.Normal)
{
ShowInTaskbar = true;
}
}
}
I want this form to begin minimized, and I want to show the taskbar icon only when the form is not minimized. But when I run this i receive a StackOverflowException. I think that the ShowInTaskbar = false is calling the resize method.
Place your automatic minimization in the “Load” event, instead of the constructor.
I’m not entirely sure why this prevents a stack overflow, but as soon as I find out, I’ll update the answer. I’ve tested it after reproducing the issue and can confirm that it works!