0

i have an mdi parent and mdi child and i want to know if what condition should i put to call the right class for this .

senario was i got a button in mdi parent (selectall) then i want to use that button for the active mdi child .

lets say:

private void iSelectAll_ItemClick(object sender,  e)
        {
            Form DtexteditoR = new DtexteditoR();
            //DtexteditoR.Show();

            if (DtexteditoR.MdiChild == true)
            {
                    rtb.SelectAll();
            }

        }

but a error

Operator == cannot be applied to operands of type 'System.Windows.Forms.Form' and 'bool'

appears ... what should i do?

leppie
  • 115,091
  • 17
  • 196
  • 297
Elegiac
  • 366
  • 10
  • 25

2 Answers2

3

You need Form.IsMdiChild to check if the form is Mdi Child.

Gets a value indicating whether the form is a multiple-document interface (MDI) child form.

private void iSelectAll_ItemClick(object sender,  e)
{
    Form DtexteditoR = new DtexteditoR();
    //DtexteditoR.Show();

    if (DtexteditoR.IsMdiChild)
    {
            rtb.SelectAll();
    }

}

To check for MdiContainer use Form.IsMdiContainer Property

Habib
  • 219,104
  • 29
  • 407
  • 436
  • it worked sir thanks! ill accept it after 5mins . but 1more thing sir . is it possible i can control a tool from mdi child to mdi parent? rtb was from mdi child and that control was from mainform which served as mdi parent .but the thing was rtb wasnt recognize in mdi parent . is there a way i can call a tool from mdichild to mainform? – Elegiac May 10 '13 at 05:16
  • @Elegiac, you are welcome, for your other question, search for `passing data between forms - winform`, this is a comon problem and you will find lots of information about it, here is a starting point http://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp and also this http://stackoverflow.com/questions/280579/how-do-i-pass-a-value-from-a-child-back-to-the-parent-form – Habib May 10 '13 at 05:18
0

write a form class that inherited from Form class and implement following method( MasterForm) : method in master form class of childs : selectAll

public class  MasterForm:Form
{
public virtual void SelectAll()
{
}
}

each child form must inhertated from MasterForm and override SelectAll Method

public class Child1:MasterForm
{
public override void SelectAll()
{
    this.rtb.SelectAll();
 }
}

in parent form in button click body

if(this.ActiveMdiChild!=null)
{
        MasterForm frm =(MasterForm) this.ActiveMdiChild;     
      frm.SelectAll();
}
mojtaba
  • 339
  • 1
  • 4
  • 17