子formで親formの変数を取得したいです
(と言う名前は存在しません)と出てきます
どうすればいいですか
お願いします。
form1
C#
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Threading.Tasks; 9using System.Windows.Forms; 10 11namespace WindowsFormsApp1 12{ 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void button1_Click(object sender, EventArgs e) 21 { 22 string n1 = textBox1.Text; 23 } 24 } 25}
C#
1namespace WindowsFormsApp1 2{ 3 partial class Form1 4 { 5 /// <summary> 6 /// Required designer variable. 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// Clean up any resources being used. 12 /// </summary> 13 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows Form Designer generated code 24 25 /// <summary> 26 /// Required method for Designer support - do not modify 27 /// the contents of this method with the code editor. 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.textBox1 = new System.Windows.Forms.TextBox(); 32 this.button1 = new System.Windows.Forms.Button(); 33 this.SuspendLayout(); 34 // 35 // textBox1 36 // 37 this.textBox1.Location = new System.Drawing.Point(1, 0); 38 this.textBox1.Name = "textBox1"; 39 this.textBox1.Size = new System.Drawing.Size(100, 19); 40 this.textBox1.TabIndex = 0; 41 // 42 // button1 43 // 44 this.button1.Location = new System.Drawing.Point(108, 0); 45 this.button1.Name = "button1"; 46 this.button1.Size = new System.Drawing.Size(75, 23); 47 this.button1.TabIndex = 1; 48 this.button1.Text = "button1"; 49 this.button1.UseVisualStyleBackColor = true; 50 this.button1.Click += new System.EventHandler(this.button1_Click); 51 // 52 // Form1 53 // 54 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 55 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 56 this.ClientSize = new System.Drawing.Size(284, 261); 57 this.Controls.Add(this.button1); 58 this.Controls.Add(this.textBox1); 59 this.Name = "Form1"; 60 this.Text = "Form1"; 61 this.ResumeLayout(false); 62 this.PerformLayout(); 63 64 } 65 66 #endregion 67 68 private System.Windows.Forms.TextBox textBox1; 69 private System.Windows.Forms.Button button1; 70 } 71}
form2
C#
1// 2 // label1 3 // 4 this.label1.AutoSize = true; 5 this.label1.Location = new System.Drawing.Point(1, 1); 6 this.label1.Name = "label1"; 7 this.label1.Size = new System.Drawing.Size(35, 12); 8 this.label1.TabIndex = 0; 9 this.label1.Text = n1;
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。