Referencing control on one form from another form

后端 未结 8 2040
轻奢々
轻奢々 2020-12-12 01:30

As you can guess, I\'m kind of new to .NET and just want to reference a control on one form from another.

Usually I would just do Form.Control.Property but that does

8条回答
  •  孤城傲影
    2020-12-12 01:51

    You should be able to make whatever you need to reference outside the form public. In many cases that's all that's needed.

    Sometimes, it's useful to create a separate public property or method. And have the method take care of the details. For example, if you just want to able able to access the text, you could create a property something like this (in C#).

    public string CustomerNo
    {
        get
        {
            return txtCustomerNo.Text;
        }
        set
        {
            txtCustomerNo.Text = value;
        }
    }
    

提交回复
热议问题