form1获取form2中的string 求代码,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要求,单击form1中按钮,出现form2窗口,单击form2中按钮,将form2中textbox中文字传到from1中。 通过参数传递。 Form1 f = new Form2(Para); 两个Format 必须都存在; 传递给Form1是什么情况,你没有说明,也就无法回答! 方式很多,可以在 form2 里引发一个事件, form1 里订阅这个事件也可以在 form2 里直接调用 form1 的方法,或者干脆把 form1 的 textbox 传给 form2怎么省事怎么来 传递给form1的lable给代码吧 using System;using System.Windows.Forms; class Form1 : Form { Form1() { Label lbl = new Label(); lbl.Parent = this; Button btn = new Button(); btn.Parent = this; btn.Text = "新窗口(&N)"; btn.Top = 30; btn.Click += delegate { new Form2(lbl).ShowDialog(); }; } static void Main() { Application.Run(new Form1()); } }class Form2 : Form{ public Form2(Label lbl) { TextBox tbx = new TextBox(); tbx.Parent = this; Button btn = new Button(); btn.Parent = this; btn.Text = "应用(&A)"; btn.Top = 30; btn.Click += delegate { lbl.Text = tbx.Text; }; }} Form2(lbl)有没有其它方法啊,我想这样:单击form1中的菜单,出现form2,在form2中输入文字,单击按钮,关闭form2,form1中获得form2中输入的文字 using System;using System.Windows.Forms; class Form1 : Form { Form1() { Label lbl = new Label(); lbl.Parent = this; Button btn = new Button(); btn.Parent = this; btn.Text = "新窗口(&N)"; btn.Top = 30; btn.Click += delegate { Form2 form2 = new Form2(); form2.ShowDialog(); lbl.Text = form2.tbx.Text; }; } static void Main() { Application.Run(new Form1()); } }class Form2 : Form{ public TextBox tbx; public Form2() { tbx = new TextBox(); tbx.Parent = this; Button btn = new Button(); btn.Parent = this; btn.Text = "确定(&A)"; btn.Top = 30; btn.DialogResult = DialogResult.OK; }} 还可以把 form2 弄成模式对话框,看情况定,你怎么会想要码呢,我一直想要无码的 form1 private void button1_Click(object sender, EventArgs e) { Form2 f2 = new Form2(); f2.ShowDialog(); label1.Text = AppDomain.CurrentDomain.GetData("txt").ToString(); }form2 private void button1_Click(object sender, EventArgs e) { AppDomain.CurrentDomain.SetData("txt", textBox1.Text); } 窗体间传值方式很多 public partial class Form1 : Form { public Form1() { InitializeComponent(); } public string TextBox1Text { set { this.textBox1.Text = value; } get { return this.textBox1.Text; } } private void button1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(this); } } public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { Form1 frm1 = (Form1)this.Owner; frm1.TextBox1Text = this.textBox2.Text; this.Close(); } } 通过 ShowDialog()进行传值;通过改造构造函数进行传值通过公共静态类进行传值;通过绑定事件进行传值;使用Attribute参考 关于多页面浏览器关闭页面时的提示问题 关于在非UI线程中,Show一个窗体无法显示的问题?Xml相关问题 大家看看这个pictureBox有什么问题吗,怎么显示红叉 vs08的程序升级到vs10后如何打包? 问一下,我的VS.net2008的代码里,所有的大写都被替换成小写了,怎么办? 窗体权限验证 怎么生成静态页 setInterval问题,在线等...... 郁闷!把数据连接做成DLL,居然用ULTRAEDIT打开就可以看到数据库连接字串和SQL语句 visual c# 、VB 求一个excel导出问题? 一个datagridview的编辑删除问题
单击form1中按钮,出现form2窗口,
单击form2中按钮,将form2中textbox中文字传到from1中。
Form1 f = new Form2(Para);
两个Format 必须都存在;
传递给Form1是什么情况,你没有说明,也就无法回答!
给代码吧
using System.Windows.Forms; class Form1 : Form
{
Form1()
{
Label lbl = new Label();
lbl.Parent = this;
Button btn = new Button();
btn.Parent = this;
btn.Text = "新窗口(&N)";
btn.Top = 30;
btn.Click += delegate { new Form2(lbl).ShowDialog(); };
}
static void Main()
{
Application.Run(new Form1());
}
}class Form2 : Form
{
public Form2(Label lbl)
{
TextBox tbx = new TextBox();
tbx.Parent = this;
Button btn = new Button();
btn.Parent = this;
btn.Text = "应用(&A)";
btn.Top = 30;
btn.Click += delegate { lbl.Text = tbx.Text; };
}
}
有没有其它方法啊,
我想这样:
单击form1中的菜单,
出现form2,
在form2中输入文字,
单击按钮,
关闭form2,
form1中获得form2中输入的文字
using System;
using System.Windows.Forms; class Form1 : Form
{
Form1()
{
Label lbl = new Label();
lbl.Parent = this;
Button btn = new Button();
btn.Parent = this;
btn.Text = "新窗口(&N)";
btn.Top = 30;
btn.Click += delegate
{
Form2 form2 = new Form2();
form2.ShowDialog();
lbl.Text = form2.tbx.Text;
};
}
static void Main()
{
Application.Run(new Form1());
}
}class Form2 : Form
{
public TextBox tbx;
public Form2()
{
tbx = new TextBox();
tbx.Parent = this;
Button btn = new Button();
btn.Parent = this;
btn.Text = "确定(&A)";
btn.Top = 30;
btn.DialogResult = DialogResult.OK;
}
}
还可以把 form2 弄成模式对话框,看情况定,你怎么会想要码呢,我一直想要无码的
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog();
label1.Text = AppDomain.CurrentDomain.GetData("txt").ToString();
}form2
private void button1_Click(object sender, EventArgs e)
{
AppDomain.CurrentDomain.SetData("txt", textBox1.Text);
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public string TextBox1Text
{
set { this.textBox1.Text = value; }
get { return this.textBox1.Text; }
} private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show(this);
}
} public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private void button2_Click(object sender, EventArgs e)
{
Form1 frm1 = (Form1)this.Owner;
frm1.TextBox1Text = this.textBox2.Text;
this.Close();
}
}
通过改造构造函数进行传值
通过公共静态类进行传值;
通过绑定事件进行传值;
使用Attribute
参考