ぽとペタ開発は楽でいいのですが、手動で書く場合はどのようにしたらいいのかと思い実践しています。
わからないのが、配置したボタンのイベントハンドラで配置してあるラベルのTextプロパティを書き換えたいのですが、作ったラベルにアクセスできません。
どのようにすればいいのか、どういう仕組なのか(どこにラベルがいるのか?)を教えていただけますでしょうか。(語彙がなくて申し訳ないです)
また、コード全体で推奨される他の書き方や慣例等がある場合も教えていただけますと幸いです。
よろしくお願いします。
C#
1using System; 2using System.Drawing; 3using System.Windows.Forms; 4 5class Program : Form 6{ 7 static void Main() 8 { 9 Application.Run(new Form1()); 10 } 11} 12 13class Form1 : Form 14{ 15 public Form1() 16 { 17 Width = 640; 18 Height = 480; 19 Text = "Windows Form Application Sample"; 20 21 Label myLabel1 = new Label(); 22 myLabel1.Location = new Point(10, 10); 23 myLabel1.Size = new Size(170, 30); 24 myLabel1.Text = ("ボタンを押すと変化します。"); 25 Controls.Add(myLabel1); 26 27 Button myButton1 = new Button(); 28 myButton1.Location = new Point(440, 400); 29 myButton1.Size = new Size(170, 30); 30 myButton1.Text = ("ボタン"); 31 myButton1.Click += new EventHandler(this.myButton1_Clicked); 32 Controls.Add(myButton1); 33 34 35 } 36 37 private void myButton1_Clicked(object sender, EventArgs e) 38 { 39 } 40} 41
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/15 19:00