0

In my application, I need to set the value of the TextBox control in the MDIParent form from one of the event in the child form

I tried this;

        public string textboxvalue { 
        get { return textBox2.Text; } 
        set { textBox2.Text = value; } }

in the MDIParent and used the following code in the child form event

        MDIParent1 mdiparent = new MDIParent1();
        mdiparent.textboxvalue = webBrowser1.Url.ToString();

this is not working; kindly help...

Jameer Basha
  • 61
  • 1
  • 9

2 Answers2

0

This is not working because you are setting the text value on the new instance of your parent form. Do it like this way-

Create the child class such that it contains the owner form and then setting the owner text value will do your purpose solved.

public class MDIParent : Form
{
    public void CreateChild()
    {
        ChildForm child = new ChildForm(this);
    }

    public string textboxvalue
    {
        get { return textBox2.Text; }
        set { textBox2.Text = value; }
    }
}

public class ChildForm : Form
{
    private Form _frmParent;

    public ChildForm(Form parent)
    {
        _frmParent = parent;
        // IntializeComponent();
    }

    public void SetText()
    {
        if (_frmParent != null)
        {
            _frmParent.textboxvalue = webBrowser1.Url.ToString();
        }
    }
}
Rohit Prakash
  • 1,975
  • 1
  • 14
  • 24
0

add this code in the child form

 ((MDIParent1)this.MdiParent).textboxvalue = webBrowser1.Url.ToString();
Ginish
  • 191
  • 1
  • 4
  • I have added this to the child form. Still it is not updating the textBox value in the MDIParent form – Jameer Basha Feb 16 '15 at 14:17
  • in the MDIParent form have you set MdiParent property of child form? 'code' childform frm = new childform (); frm.MdiParent = this; frm.Show(); – Ginish Feb 17 '15 at 06:02