を呼び出す必要があります。私はそれを人々に解決しました!
私はページ上にListBoxを持ち、SelectedIndexが変更されたときに実行される関数を持っていました。フォームを閉じると、-1のSelectedIndexが渡され、2回目が閉じられました。だから、それを修正するために、単純に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
おそらく、200行以上のコードを投稿する前に、どの行が原因であるかを調べるべきです。この動作がなくなるまで、行をコメントアウトしてみてください。 e.cancel = trueのようなものを探すこともできます。 –
@HungryMind:キーボードやマウスの問題ではなく、その行を削除するとうまく動作しますが、コードを実行する必要がありますアプリケーションは終了/終了しています。 –