D
D
Dmitry Kovalev2021-03-27 21:50:17
C++ / C#
Dmitry Kovalev, 2021-03-27 21:50:17

Label is not added through the code, what's the problem?

There is a class Syntax which describes a function that returns an object of type Label with characteristics (location, size, font, etc.). In the main file, in the function that describes the actions, this function is called every time the code changes, which is equal to the local Label. The label itself does not appear no matter how you change it.
Function call:

//...
Label syntaxLabel = Syntax.AddLabelOnText();
syntaxLabel.AccessibleName = "syntaxLabel";
Controls.Add(syntaxLabel);


The syntax class function itself:
public Label AddLabelOnText()
        {
            Label syntaxLabel = new Label();

            syntaxLabel.Text = "aaa";
            syntaxLabel.ForeColor = Color.White;
            syntaxLabel.Location = new Point(560, 13);
            syntaxLabel.BorderStyle = BorderStyle.Fixed3D;
            syntaxLabel.UseMnemonic = true;
            syntaxLabel.Size = new Size(10, 10);
            syntaxLabel.AccessibleName = "syntaxLabel";
            syntaxLabel.Visible = true;

            return syntaxLabel;
        }


UPD: I tried to create a label without a function and still nothing:
Label labela = new Label()
            {
                Text = "First Name",
                Location = new Point(100, 100),
                TabIndex = 10
            };

            Controls.Add(labela);

And at the initialization of the form added and in the function triggered when the text changes. Nothing. Possibly, I messed up in the properties of the form, but there seems to be nothing like that there.

UPD2 : MCVE

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BasiC2k, 2021-03-27
@BasiC2k

Well, you added a new element to the collection of controls. Good.
And on the form (panel or whatever you have) added?
Turn on the designer mode, see what actions are performed when adding a control.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question