O código é esse mesmo, funciona sem problemas:
Code Snippet
private void button1_Click(System.Object sender, System.EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName);
MessageBox.Show(sr.ReadToEnd());
sr.Close();
}
}
Provavelmente você tenha adicionado o Button e em seguida digitado o código diretamente. O Ideal seria você clicar 2x no Button para que o Visual Studio criar o código do Evento (Button1_Click).
Para resolver seu problema, abra o arquivo do seu Formulários, Form1.Designer.Cs (Lembrando que Form1 em seu projeto estará com o nome que você definiu), após abrir esse arquivo procure por this.button1 ( estarar na #region Windows Form Designer generated code) e adicione
Code Snippet
this.button1.Click += new System.EventHandler(this.button1_Click);
Ficará algo assim:
Code Snippet
#region
Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(199, 25);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);