第二次进行编辑后刷新表单 [英] Refresh a form after making edits on second

查看:87
本文介绍了第二次进行编辑后刷新表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,一旦更改完成,我当前正在尝试刷新表单的每个人.在我的第一个表单上,我按下创建"按钮,这将打开另一个表单,即form2.第二个窗体将具有输入字段,并允许您输入填充第一个窗体上的组合框的值.在第二个表单上,有一个更新"按钮,我希望在第一个表单上按下更新后刷新第一个表单.

hey everyone I am currently trying to refresh a form once changes are done on a second. On my first form I press a button "create" that will open another form, form2. This second form will have input fields and allows you to input values that populate comboboxes on the first form. On the second form there is a button "update" I would like the fist form to refresh once update is pressed on the first.

我知道有this.refresh();,但是我不确定这是否对我有用.我正在尝试遵循以下原则:

I know there is this.refresh();, but I'm not sure if this is useful for me. I am trying to something along the lines of:

在form2上-

Private void Form2UpdateButton_Click
{
  //do update stuff
  Form1_load.Refresh();
}

也许

private void Form2UpdateButton_Click
    {
    //do update stuff
    Form1.close();
    Form1.Open();
    }

我对C#还是很陌生,并且对2种形式进行交互对我来说是一个相当复杂的概念,所以请让我知道我是否以错误的方式进行操作.我的刷新可能在错误的位置,但是我认为这是我想要的.

I am still pretty new to C# and interacting 2 forms together is a rather complex concept to me so please let me know if I am going about this the wrong way. My refresh may be in the wrong spot, but I think this is what I want.

推荐答案

一种方法是将Form1的引用传递给Form2,如下所示:

One way is to pass a reference of Form1 to Form2, like this:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void buttonLaunchForm_Click(object sender, EventArgs e)
    {
        Form2 form2 = new Form2();
        form2.LauncherForm = this;

        form2.Show();
    }

    public void RefreshFormData()
    {
         // Refresh
    }
}

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    public Form1 LauncherForm { set; get; }

    private void buttonUpdate_Click(object sender, EventArgs e)
    {
        // do your normal work then:

        LauncherForm.RefreshFormData();
    }
}

以上技术称为属性注入" ;

这篇关于第二次进行编辑后刷新表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆