为什么在将form1.ShowInTaskBar设置为false时它会抛出异常?

时间:2016-02-24 18:36:30

标签: c# .net winforms

我想在某些情况下在托盘图标中启动表单。 所以在构造函数中我做了:

public Form1()
{
    InitializeComponent();

    settingsFileDirectory = Path.GetDirectoryName(Application.LocalUserAppDataPath) +
        settingsFileDirectory;
    if (!Directory.Exists(settingsFileDirectory))
    {
        Directory.CreateDirectory(settingsFileDirectory);
    }
    settingsFile = Path.Combine(settingsFileDirectory,settingsFile);
    if (!File.Exists(settingsFile))
    {
        File.Create(settingsFile);
    }

    string[] values = System.IO.File.ReadAllText(settingsFile).Split(',');
    downloadonstart = Convert.ToBoolean(Convert.ToInt32(values[0]));
    loadonstart = Convert.ToBoolean(Convert.ToInt32(values[1]));
    startminimized = Convert.ToBoolean(Convert.ToInt32(values[2]));
    displaynotifications = Convert.ToBoolean(Convert.ToInt32(values[3]));

    lvnf = new ListViewNF();
    lvnf.Location = new Point(250, 18);
    lvnf.Size = new Size(474, 168);
    lvnf.View = View.Details;
    this.SuspendLayout();
    lvnf.LabelEdit = true;
    lvnf.Columns.Add("From", 100, HorizontalAlignment.Left);
    lvnf.Columns.Add("Subject", 200);
    lvnf.Columns.Add("Date", 300);
    lvnf.Sorting = SortOrder.None;
    lvnf.ColumnClick += lvnf_ColumnClick;
    lvnf.Click += lvnf_Click;
    this.Controls.Add(lvnf);
    this.ResumeLayout(false);
    label8.Visible = false;
    pbt.Size = new Size(216, 10);
    pbt.Location = new Point(8, 330);
    pbt1.Size = new Size(396, 10);
    pbt1.Location = new Point(250, 198);
    this.Controls.Add(pbt1);
    groupBox1.Controls.Add(pbt);
    pbt.Text = "0%";
    pbt1.Text = "0%";
    //LoadFullMessages();
    if (startminimized == true)
    {
        this.WindowState = FormWindowState.Minimized;
    }
    if (loadonstart == true)
    {
        backgroundWorker2.RunWorkerAsync();
    }
    if (downloadonstart == true)
    {
        backgroundWorker1.RunWorkerAsync();
    }
}

然后在Form1_Resize事件中我做了这个:

private void Form1_Resize(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        this.Hide();
        this.ShowInTaskbar = false;
    }
}

该例外的原因是:

this.ShowInTaskbar = false;
  

未处理的类型' System.StackOverflowException'发生在System.Windows.Forms.dll

然后我点击休息,我看到了:

Exception

我做错了什么?

0 个答案:

没有答案