public partial class Form1 : Form { private void button1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(this); } } public partial class Form2 : Form { private void button1_Click(object sender, EventArgs e) { Form1 frm1 = (Form1)this.Owner; ((TextBox)frm1.Controls["textBox1"]).Text = this.textBox2.Text; this.Close(); } }
楼上的就可以 你也可以这样写 //Form1 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace TestShow { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public Form1(string str) { InitializeComponent(); this.label1.Text = str; } private void button2_Click(object sender, EventArgs e) { Form2 fr2 = new Form2(); fr2.Show(); this.Visible = false; } //========================= //Form2 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace TestShow { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form1 fr1 = new Form1(textBox1.Text); fr1.Show(); this.Visible = false; } } }
{
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show(this);
}
} public partial class Form2 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Form1 frm1 = (Form1)this.Owner;
((TextBox)frm1.Controls["textBox1"]).Text = this.textBox2.Text;
this.Close();
}
}
你也可以这样写
//Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace TestShow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Form1(string str)
{
InitializeComponent();
this.label1.Text = str;
}
private void button2_Click(object sender, EventArgs e)
{
Form2 fr2 = new Form2();
fr2.Show();
this.Visible = false;
}
//=========================
//Form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace TestShow
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 fr1 = new Form1(textBox1.Text);
fr1.Show();
this.Visible = false;
}
}
}
先运算 再赋值如果你用如梦大哥的方法就是这样的 public partial class Form2 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Form1 frm1 = (Form1)this.Owner;
string str="";
//做运算,比如加上"--CSDN"
str=this.textBox2.Text+"--CSDN";
((TextBox)frm1.Controls["textBox1"]).Text = str;
this.Close();
}
}