Access to child form controls

I want to change the text in the text box to parentform from childform. I set the text box

modifiers = public I have an extra function entry in parentform

public TextBox txtbox
{
  get
  {
    return  mybox;
  }
  set
  {
    mybox= value;
  }
}

in childish form when writing this.ParentForm. (not visible mybox). what i'm missing. Yours faithfully,

+3
source share
3 answers

Since it ParentFormwill return Form, not your form, you need to execute it before you can access any of your custom properties:

((MyForm)this.ParentForm).textbox = "new text!";

In addition, you install the entire control, not just text.

Try this to expose only a text property:

public string txtbox
{
  get
  {
    return  mybox.Text;
  }
  set
  {
    mybox.Text = value;
  }
}
+4
source

, , ParentForm Form, txtbox. ParentForm (, Form1), :

((Form1)this.ParentForm).txtbox
+3

A random assumption, without seeing the real code: myboxmost likely, not declared public.

Edit: Or, yes, yes, as Andrew says, you do not put ParentForm in your type of the parent form.

0
source

Source: https://habr.com/ru/post/1783233/


All Articles