What is the correct way to access user controls in Winform?

I created this user control:

enter image description here

I added that User Control to the main form, and now I want to configure it. Therefore, I will need to add text to these 3 buttons, the text in the shortcut, fill in the ListBox and set the "Click" buttons for the buttons.

What is the right way to do this?

I looked at the website, and apparently the way to do this is to add public properties to the user control, which will provide me with an individual control property.

Sort of:

    public string Button1Text
    {
        get
        {
            return btn1.Text;
        }
        set
        {
            btn1.Text = value;
        }
    }

If I go this route, I will have to add quite a few public properties to this simple user element.

, ?

    public Button MyButton1
    {
        get { return this.btn1; }
        set { this.btn1 = value; }
    }

, .

+3
3

. () , .

+3

- . , .

+2

, , , Parent.

If you use the second method, anyone who wants to use your control will be able to move and resize individual controls within your control. Then this is really not a custom control, but rather a panel that is harder to use than a panel. I cannot think of any reason why it is possible to allow the Parent to move through the individual elements in the subcontrol.

+1
source

All Articles