重复执行按钮事件的问题通常是由于事件订阅的重复导致的。解决方法有以下几种:
private void button1_Click(object sender, EventArgs e) { // 先取消订阅事件 button1.Click -= button1_Click; // 执行按钮事件的逻辑 // 重新订阅事件 button1.Click += button1_Click; } private bool isProcessing = false; private void button1_Click(object sender, EventArgs e) { if (isProcessing) { return; } isProcessing = true; // 执行按钮事件的逻辑 isProcessing = false; } public Form1() { InitializeComponent(); button1.Click += button1_Click; } private void Form1_Load(object sender, EventArgs e) { // 其他初始化逻辑 }