这是我的代码,由于某种原因,按钮二不会触发,按钮一会触发,当我将按钮 2 中的代码放入其中时,它会在那里工作。关于让按钮一和二都在点击时工作的语法,我缺少什么?我学习 c# 大约 2 周,所以这对我来说是全新的,我不明白为什么这段代码不应该工作。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
string filePath = null;
public Form1()
{
InitializeComponent();
}
//Method to check database connection
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("button1.Click was raised.");
}
//Method to select a file
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog file = new OpenFileDialog();
if (file.ShowDialog() == DialogResult.OK)
{
filePath = file.FileName;
}
}
}
}