Home>

【the first method:】

first step:

Create interface iform, the parent form inherits this interface

public interface iform
{
    void refreshform ();
}

The second step:

The parent form implements the methods in the interface,Write refresh code in methods that implement the interface

form2 f=new form2 ();
f.owner=this;
f.showdialog ();

third step:

Called in a subform,Refresh method

(this.owner as iform) .refreshform ();

【The second method:】

1. The refresh method refreshform () defined in the parent form

2. When the click event shows a sub-form,code show as below:

form form=new form ();
form.show (this);

3. In the click event of the subform,code show as below:

(this.owner as form) .refreshform ();

[The third method:]

Solution by event:

Defined in the subform:

public delegate void sendmessage (string message);
public event sendmessage sendto;

Main form:

childform frm=new childform ();
frm.sendto +=new childform.sendmessage (sendargs);
frm.showdialog (this);
private void sendargs (string message) //The main form receives the message
{messagebox.show ("The main form has received a message:" + message);}

Subform test:

if (this.sendto!=null) this.sendto ("Did the main form receive it?");

[Fourth method:]

By reference:

The following example shows how to implement your function by reference type:

Defined in the subform:

protected mainform parentfrom=null;//Main form

New constructor:

public childform (mainform parent)
{
initializecomponent ();
this.parentfrom=parent;//reference
}

A click in the main form:

childform frm=new childform (this);
frm.showdialog (this);

Subform test:

void ... click (....)
{
this.text="Test Reference";
if (this.parentfrom!=null) this.parentfrom.text +="-" + this.text;//.......
}
c
  • Previous Mysql/MariaDB is in a progress bar state during startup and causes the failure and the solution
  • Next Example analysis of tree and scroll bar usage in swing