窗体间传值 (winform)*蔡丝军*
嘟嘟!想起我们 一起写 代码。页面传值 最好 玩。是到如今 让我写winform的窗体传值 呜呜,, 这个苦啊。。。。
嘿嘿!但也不是没办法。问题总比办法少的,对吧? 没有 response ,request ,Cookie,session、Server.Transfer() 等,我就用。。。。。。。。。
嘻嘻!!我告诉大家一个好办法 ,特简单!
操作:首先点击form1的按钮,然后跳转到form2中来。在form2中编辑完毕之后,点击传值按钮。将form2编辑好的数据,传到form1中去。
效果图如下:
form2
form1 

代码也很少,只有短短几句代码就OK乐>
form1:
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8
9 namespace test001
10 {
11 public partial class Form1 : Form
12 {
13 public Form1()
14 {
15 InitializeComponent();
16 }
17
18 private void button1_Click(object sender, EventArgs e)
19 {
20 Form2 f2 = new Form2();
21 f2.ShowDialog(this);
22 }
23 }
24 }
form2:
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8
9 namespace test001
10 {
11 public partial class Form2 : Form
12 {
13 public Form2()
14 {
15 InitializeComponent();
16 }
17
18
19 private void button1_Click_1(object sender, EventArgs e)
20 {
21 Form1 f1 = (Form1)this.Owner;
22 f1.textBox1.Text = this.textBox1.Text;
23 f1.textBox2.Text = this.textBox2.Text;
24 this.Close();
25 }
26 }
27 }
OK!!!!!简单的传值就弄好了,你学会了吗?
如有需要——至QQ:1318259375
浙公网安备 33010602011771号