D
D
dotrem2014-10-15 10:44:10
C++ / C#
dotrem, 2014-10-15 10:44:10

How to create a custom control?

I made a custom UserControl , added my fields:

public string OffText { set; get; }
public string OnText { set; get; }
public bool State { set; get; }

After, I added this control to the form in the studio interface and set the values ​​​​of the OffText and OnText fields , I set the State programmatically.
In the constructor I have:
public FakeToggleSwitch()
    {
        InitializeComponent();

        if (State)
        {
            CheckEdit.Text = OnText;
        }
        else
        {
            CheckEdit.Text = OffText;
        }
    }

But, in debug mode, in the constructor I see that OnText and OffText are null . Accordingly, I do not see it on the test form.
My knowledge, unfortunately, is not enough to ask a competent question about what is going wrong.
How would you like it to work. I set the State field using the value from the BindingSource. And accordingly I want to change the Text field of the checkbox based on the State value.
I ask for advice, examples and what you can read!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
follow39, 2014-10-15
@follow39

That's right, you don't assign values ​​anywhere, so you have null everywhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question