How to access properties of a usercontrol in C#

前端 未结 5 1326
鱼传尺愫
鱼传尺愫 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:20

    I recently had some issues doing this with a custom class:

    A user control had a public property which was of a custom class type. The designer by default tries to assign some value to it, so in the designer code, the line userControlThing.CustomClassProperty = null was being automatically added.

    The intent was to be able to provide the user control with a custom class at any point while running the program (to change values visible to the user). Because the set {} portion did not check for null values, various errors were cropping up.

    The solution was to change the property to a private one, and use two public methods to set and get the value. The designer will try to auto-assign properties, but leaves methods alone.

提交回复
热议问题