How to access properties of a usercontrol in C#

前端 未结 5 1329
鱼传尺愫
鱼传尺愫 2020-12-06 09:58

I\'ve made a C# usercontrol with one textbox and one richtextbox.

How can I access the properties of the richtextbox from outside the usercontrol.

For exampl

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 10:21

    You need to make a public property for the richtextbox, or expose some other property that does the job of setting the richtextbox text like:

    private RichTextBox rtb;
    
    public string RichTextBoxText
    {
        get
        {
            return rtb.Text;
        }
        set
        {
            rtb.Text = value;
        }
    }
    

提交回复
热议问题