Use the interface mode to refresh a child form

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.