参考代码Form1using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static string fortxt; private void Form1_Load(object sender, EventArgs e) { fortxt = textBox1.Text; }Form2使用textBox1代码,我用的是label1控件显示 label1.Text = Form1.fortxt.ToString();Form3如此类退......
报错 Form1不包含对textBox1的定义
private System.Windows.Forms.TextBox textBox1;
改为
public static System.Windows.Forms.TextBox textBox1;在InitializeComponent()里把
this.textBox1 = new System.Windows.Forms.TextBox();
改为
textBox1 = new System.Windows.Forms.TextBox();
相应的textBox1的属性初始化部分也要把this.去掉
然后就可以在Form2中这样调用textBox1了
Form1.textBox1.Text = "test";
请参考//Form1.cs
public partial class Form1 : Form
{
public string MyText
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this);
frm.ShowDialog();
}
}//Form2.cs
public partial class Form2 : Form
{
Form1 form1;
public Form2()
{
InitializeComponent();
}
public Form2(Form1 f)
{
InitializeComponent();
this.form1 = f;
}
private void button1_Click(object sender, EventArgs e)
{
form1.MyText = "abc";
}
}
amandag(高歌)
他们的办法应该都很好
amandag(高歌) 很多窗体都需要调用这个控件 这样做的话是不是会很麻烦
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public static string fortxt;
private void Form1_Load(object sender, EventArgs e)
{
fortxt = textBox1.Text;
}Form2使用textBox1代码,我用的是label1控件显示
label1.Text = Form1.fortxt.ToString();Form3如此类退......