Form1にはtextBox1とbutton1を配置、Form2にはlabel1を配置し、
Form1のtextBox1に文字を入力してbutton1を押すと、
Form2のlabelに入力した文字を表示したいと思っています。
現在、「form2.label1.Text = textBox1.Text;」の行で
「'Form2.label1'はアクセスできない保護レベルになっています」という
エラーが出ているのですが、ネットで検索しても理解出来ないので教えて
頂けないでしょうか。宜しくお願い致します。
c#
1 2// Fom1.cs 3using System; 4using System.Collections.Generic; 5using System.ComponentModel; 6using System.Data; 7using System.Drawing; 8using System.Linq; 9using System.Text; 10using System.Threading.Tasks; 11using System.Windows.Forms; 12 13namespace form_test3 { 14 public partial class Form1 : Form { 15 public Form1() { 16 InitializeComponent(); 17 } 18 19 private void button1_Click(object sender, EventArgs e) { 20 using (var form2 = new Form2()) { 21 form2.label1.Text = textBox1.Text; 22 form2.Show(); 23 } 24 } 25 } 26} 27 28 29// Form2.cs 30using System; 31using System.Collections.Generic; 32using System.ComponentModel; 33using System.Data; 34using System.Drawing; 35using System.Linq; 36using System.Text; 37using System.Threading.Tasks; 38using System.Windows.Forms; 39 40namespace form_test3 { 41 public partial class Form2 : Form { 42 43 public Form2() { 44 InitializeComponent(); 45 } 46 } 47}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/25 07:57