namespace xx { public partial class test: Form { form2.x=............. }
}
(1) 使用替換控制權來進行傳遞 Form1_button1_click value_transfer.Form2 myfrm=new Form2("ttt"); myfrm.Owner=this; myfrm.ShowDialog();Form2_button2_click //通過移交控制權來傳遞參數 value_transfer.Form1 myfrm=new Form1(); myfrm=(Form1)this.Owner; myfrm.textBox1.Text=this.textBox1.Text; //myfrm.textBox1.Text=myfrm.add(3,5).ToString(); //add和myfrm.textBox1設置成PUBLIC才可以訪問的。(2) 通過FORM. DialogResult來進行參數傳遞 Form1_button1_click value_transfer.Form2 myfrm=new Form2(); if (myfrm.ShowDialog()==System.Windows.Forms.DialogResult.OK) { this.textBox1.Text =myfrm.textBox1.Text; }Form2_button1_click this.DialogResult=System.Windows.Forms.DialogResult.OK;(3) 通過類的屬性來傳遞參數 //建立公共類庫 Public class test() { //設置私有靜態字符類型 Private static string temp; Public class test() {}
Public string s { Set {this.temp=values;} Get {return this.temp;}Form2_button1_click value_transfer.Class1 myclass=new Class1(); myclass.test=this.textBox1.Text.Trim();Form1_button1_click value_transfer.Class1 myclass=new Class1(); this.textBox1.Text=myclass.test;(4) 窗體傳遞參數 FORM2(STRING ADB);
供参考,如下: 我的Form1是父窗体 Form2是子窗体 每个窗体里包含一个ListBox 然后根据Form1里的ListBox的选值改变Form2里Listbox的选值 ListBox里我设置的是1,2,3,4,5,6 6个值然后可以对应改变 Form1代码如下: Public Class Form1 Private Sub ListBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.Click Form2.ListBox1.SelectedItem = Me.ListBox1.SelectedItem End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Form2.Show() End Sub End Class Form2代码如下: Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.MdiParent = Form1
http://blog.csdn.net/tjvictor/archive/2006/06/23/824617.aspx
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2(this);
frm2.Show();
} public void Test()
{
textBox1.Text = "aaaa";
}
******************************
public partial class Form2 : Form
{
Form1 frm; public Form2(Form1 _frm)
{
InitializeComponent();
frm=_frm;
} private void button1_Click(object sender, EventArgs e)
{
frm.Test();
} private void button2_Click(object sender, EventArgs e)
{
frm.textBox1.Text = textBox1.Text;
}
}
默认为引用传递,所以很好控制
{
clear frm = new clear(this.textBox1.Text,this.textBox2.Text,this.textBox3.Text);
frm.Show();
}
public clear(string tbS1,string tbS2,string tbS3)
{
InitializeComponent();
this.textBox1.Text = tbS1;
this.textBox2.Text = tbS2;
this.textBox3.Text = tbS3;
}
这样解决的 对吗?
form2 b=new form2();
b.a=this.textbox1;
b.show();
{ public partial class test: Form
{
form2.x=.............
}
}
Form1_button1_click
value_transfer.Form2 myfrm=new Form2("ttt");
myfrm.Owner=this;
myfrm.ShowDialog();Form2_button2_click
//通過移交控制權來傳遞參數
value_transfer.Form1 myfrm=new Form1();
myfrm=(Form1)this.Owner;
myfrm.textBox1.Text=this.textBox1.Text;
//myfrm.textBox1.Text=myfrm.add(3,5).ToString();
//add和myfrm.textBox1設置成PUBLIC才可以訪問的。(2) 通過FORM. DialogResult來進行參數傳遞
Form1_button1_click
value_transfer.Form2 myfrm=new Form2();
if (myfrm.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
this.textBox1.Text =myfrm.textBox1.Text;
}Form2_button1_click
this.DialogResult=System.Windows.Forms.DialogResult.OK;(3) 通過類的屬性來傳遞參數
//建立公共類庫
Public class test()
{
//設置私有靜態字符類型
Private static string temp;
Public class test()
{}
Public string s
{
Set
{this.temp=values;}
Get
{return this.temp;}Form2_button1_click
value_transfer.Class1 myclass=new Class1();
myclass.test=this.textBox1.Text.Trim();Form1_button1_click
value_transfer.Class1 myclass=new Class1();
this.textBox1.Text=myclass.test;(4) 窗體傳遞參數
FORM2(STRING ADB);
我的Form1是父窗体
Form2是子窗体
每个窗体里包含一个ListBox
然后根据Form1里的ListBox的选值改变Form2里Listbox的选值
ListBox里我设置的是1,2,3,4,5,6 6个值然后可以对应改变
Form1代码如下:
Public Class Form1 Private Sub ListBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.Click
Form2.ListBox1.SelectedItem = Me.ListBox1.SelectedItem
End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Form2.Show() End Sub
End Class
Form2代码如下:
Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MdiParent = Form1
End Sub
End Class
f.show();
在form2 中定义
public Form1(string str1,string str2,string str3)
{
InitializeComponent();
this.textbox1.text=str1;
this.textbox2.text=str2;
this.textbox3.text=str3;
}