首页 新闻 会员 周边

winform开发中遇到一个小问题

0
[已解决问题] 解决于 2017-03-01 09:44

winform开发中,点击一个按钮之后,弹出一个新的窗口(我们叫窗口2),然后这个窗口里面有一个textbox控件个一个button控件,填完之后,点击确定后,我想让窗口1的一个方法继续执行,我该用什么来解决这种问题?

NeXT、的主页 NeXT、 | 菜鸟二级 | 园豆:295
提问于:2017-03-01 08:39
< >
分享
最佳答案
0

百度一下:windorm ShowDialog DialogResult

奖励园豆:5
starStars | 初学一级 |园豆:52 | 2017-03-01 08:59
其他回答(1)
0

我这个方法笨一点。

把Form1传给Form2。

Form1 代码

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 
10 namespace demo
11 {
12     public partial class Form1 : Form
13     {
14         public Form1()
15         {
16             InitializeComponent();
17         }
18 
19         private void button1_Click(object sender, EventArgs e)
20         {
21             Form2 _form = new Form2(this);
22             _form.ShowDialog();
23         }
24 
25         #region 窗口一要执行的方法
26         public void Method()
27         {
28             MessageBox.Show("窗口一要执行的方法");
29         }
30         #endregion
31     }
32 }

Form2 代码

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 demo
{
    public partial class Form2 : Form
    {

        Form1 form1;

        public Form2(Form1 _form)
        {
            InitializeComponent();
            form1 = _form;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            form1.Method();
        }
    }
}

 

熊猫警长 | 园豆:202 (菜鸟二级) | 2017-03-01 10:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册