這是我的代碼,由於某種原因,按鈕2不會觸發,按鈕1會發生,當我將按鈕2中的代碼放入一個代碼中時,它會在其中工作。我錯過了關於獲取按鈕一和二的語法的問題,它們都可以用於點擊?我大約花了2周的時間學習c#,所以這對我來說都是新的,我不明白爲什麼這個代碼不應該工作。在C#中讀取文件的程序:Button not working
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;
}
}
}
}
你有沒有指定的單擊事件到button2_Click方法? – Steve 2013-03-08 21:12:07
發佈的代碼不完整,沒有分配事件的跡象。該程序使用'.designer.cs'文件,該文件未發佈,因此我們無法爲您提供幫助。 – 2013-03-08 21:14:26