help,two problems with Form.

hi all.

recently i have got some problems with vs2003.

1. In A Form open B Form that how to refresh the A from or call method of A Form

like :

 B a = new B();

b.ShowDialog();

now , focus on b form that how call method of a form

2. How Create MDI model Application in .net compact framework( in ppc 2003)

thanks.




Answer this question

help,two problems with Form.

  • Razmattaz1

    First of all if you use the FormB.ShowDialog() method you wont be able to focus on another form of the application until you attend input on FormB. I guess you want to use FormB.Show() instead.

    as for calling methods on another form

    if you have FormA and FormB....

    //on FormA declaration

    class FormA:System.Windows.Forms

    {

    ...

    FormB myFormB = new FormB;

    ...

    myFormB.DoSomething(); //if you have a method called "DoSomething" on FormB

    }

    //on Form B declaration

    class FormB:System.Windows.Forms

    {

    ...

    FormA myFormA = new FormA;

    ...

    myFormA.DoSomethingElse(); //if you have a method called "DoSomethingElse"

    //on FormA

    }



  • Andreas Botsikas

    You can use events.

    For example:
    Form1 has a button on it, which shows Form2 when clicked.
    Form2 also has a button which refreshes Form1 when clicked.

    The code could be:

    //Form1
    private void button1_Click(object sender, System.EventArgs e)
    {
    Form2 f2 = new Form2();
    f2.RefreshRequiredEvent += new Form2.RefreshRequiredEventHandler(OnRefresh);
    f2.ShowDialog(this);
    }

    private void OnRefresh()
    {
    //do your refresh code here
    }

    //Form2
    public delegate void RefreshRequiredEventHandler();
    public event RefreshRequiredEventHandler RefreshRequiredEvent;

    private void button1_Click(object sender, System.EventArgs e)
    {
    if(RefreshRequiredEvent != null)
    {
    RefreshRequiredEvent();
    }
    }

  • Dave Hunt

    Use the FormA Method() as a static method, so that you can call it from FormB without making an instance of FormA



  • help,two problems with Form.