accessing controls on parentform from childform

后端 未结 3 1101
花落未央
花落未央 2021-01-14 14:53

I want to change text in textbox on parentform from childform. I set textbox

modifiers= public i have extra written a function in parentform

publ         


        
3条回答
  •  隐瞒了意图╮
    2021-01-14 15:28

    Since ParentForm will return a Form and not your form, you need to cast it before you can access any of your custom properties:

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

    Additionally, you are setting the whole control, not just the text.

    Try this, to expose the text property only:

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

提交回复
热议问题