求代码,谢谢
解决方案 »
- C#使用Microsoft.Office.Interop.Excel操作后Excel对象的释放问题
- 急,急,急oracle join 语句出错??
- 怎么获取当前网络内可用的数据库?
- 为什么主界面会没有响应啊
- 一个string 与 float 转换问题
- string为什么设计为不可更改的?
- 继承自Fluent:RibbonWindow的wpf窗体怎么去掉最大化按钮?
- 引用MYSQL.DATA.DLL的类,在用户机器上运行后无法创建对象
- 我启动了一个线程,怎么判断这个线程是否已经终止了
- 我熟悉Delphi,C/C++,对面向对象有足够的理解,现在为了适应潮流学习C#.net,请朋友们根据你们的经验和我的实际情况推荐一本好的书籍(中
- 求一个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
参考