我已經解決了它的人!
我在頁面上有一個ListBox,並且一個函數在SelectedIndex改變時運行。當我關閉表單時,它傳遞了-1的SelectedIndex,然後第二次關閉。所以,爲了解決它,我只是簡單地驗證了ListBox函數的值。
實施例:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
}
void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
變得
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
}
void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(listBox1.SelectedIndex == -1)
{
Application.Exit();
}
//Rest of the code goes here.
}
}
}
看起來像鼠標或鍵盤的問題。如果刪除ApplicationExit處理程序,你會看到同樣的行爲嗎?已解決的問題。 – hungryMind 2011-02-03 07:27:11
您應該在發佈200多行代碼之前嘗試確定導致此行的原因。嘗試註釋行,直到它不再顯示此行爲。您可能還想尋找類似於e.cancel = true – 2011-02-03 07:28:37