After searching in the network, you can find that it is convenient to use interfaces to refresh the parent form. It is easy to understand. Therefore, I am writing a blog to record it, so that I can go back and review myself in depth. A lot of things have been done by myself before, but after a long period of time it does not mean that they can be easily written, so I can only use blog articles to record my bit by bit, I will at least remember to use this scenario in a project when I look at it next time.
First, define an interface:
using System;
using System.Collections.Generic;
using System.Text;
namespace WinFormSendValue
{
public interface IForm
{
void RefreshForm();
}
}
Of course, to achieve refresh, you must first inherit the interface with the refresh function in the refreshed form ..
Public partial class KuCunYiDongDetailsAddFrm: Form, IForm
{
............... The code is omitted
}
Second, you must implement the interface method in this form.
Public void RefreshForm ()
{
This. Refresh ();
LoadBodyData (sendOrderNumber); // refresh single
LoadDetailsDate (sendOrderNumber); // refresh details, that is, refresh the dataGRIDVIEW
}
Call this method in the event where you want to open the child form. Note that the Owner attribute of the child form to be opened must be set as the form (parent)
Private void btnBodyAddDetails_Click (object sender, EventArgs e)
{
SingleAdd = new SingleDetailsAddingFrm ();
SingleAdd. Owner = this; // sets the OWNER attribute.
RefreshForm (); // refresh the parent form
SingleAdd. ShowDialog ();
New SingleDetailsAddingFrm (). ShowDialog (); // go to the inventory change Singleton details add form
}
The most important and final step is to call the code in the form as follows.
(This. Owner as IForm). RefreshForm ();
This sentence can be placed anywhere you need. For example, closing an event.