windows窗体间传递数据和方法的调用。

a窗体间传递数据和方法:

ContractedBlock.gif ExpandedBlockStart.gif Code
 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Data;
 5using System.Drawing;
 6using System.Linq;
 7using System.Text;
 8using System.Windows.Forms;
 9
10namespace 窗口间传递数据1
11ExpandedBlockStart.gifContractedBlock.gif{
12    public partial class Form1 : Form
13ExpandedSubBlockStart.gifContractedSubBlock.gif    {
14        public Form1()
15ExpandedSubBlockStart.gifContractedSubBlock.gif        {
16            InitializeComponent();
17        }

18
19        private void button2_Click(object sender, EventArgs e)
20ExpandedSubBlockStart.gifContractedSubBlock.gif        {
21            Form2 fm2 = new Form2();
22            fm2.form1 = this;
23            fm2.Show();
24        }

25        public void GetNameAddPwd(string name,string pwd)
26ExpandedSubBlockStart.gifContractedSubBlock.gif        {
27            textBox1.Text = name.Trim();
28            textBox2.Text = pwd.Trim();
29        }

30    }

31}

32


(二)这是一个注册页面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 窗口间传递数据1
{
    public partial class Form2 : Form
    {
        public Form1 form1;//在这里首先声明了一个Form1变量用来调用Form1类中的方法。并且在登陆界面中的函数中为他初始化。
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            form1.GetNameAddPwd(textBox1.Text ,textBox2 .Text );//调用Form1中的方法给登陆界面传递值
            form1.Show();
            this.Hide();
        }
    }
}



其实不仅仅可以用在传数据上,因为可以调用方法。比如在gridview中重新打开一个添加数据界面,添加数据后可以调用其主界面的方法刷新数据,这样就可以添加完成后在主界面立刻看到添加的数据。

转载于:https://www.cnblogs.com/kuwoyidai/archive/2009/09/23/1572856.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值