以下のコードをコンパイルすると「error CS1061: 'testpro.Form1' に 'btn' の定義が含まれておらず、型 'testpro.Form1' の最初の引数を受け付ける拡張メソッドが見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足しています。」
というエラーが出てしまいます。どうすればいいでしょうか??
C#
1using System; 2using System.CodeDom; 3using System.CodeDom.Compiler; 4using System.Reflection; 5using System.Windows.Forms; 6using System.Drawing; 7namespace testpro 8{ 9 static class main 10 { 11 [STAThread] 12 static void Main() 13 { 14 Application.EnableVisualStyles(); 15 Application.SetCompatibleTextRenderingDefault(false); 16 Application.Run(new Form1()); 17 } 18 } 19 public partial class Form1 : Form 20 { 21 public Form1(){ 22 Text = ""; 23 ClientSize = new Size(200,200); 24 Button btn = new Button(); 25 btn.Location = new Point(0,0); 26 btn.Font = new Font("Arial",12); 27 btn.Text = "btn"; 28 this.btn.Click += new System.EventHandler(this.btn_Click); 29 this.Controls.Add(btn); 30 } 31 32 void btn_Click(object sender, EventArgs e) 33 { 34 MessageBox.Show("hello"); 35 36 } 37 } 38}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。