There is a textbox. Its name is given as text "textBoxName" (it was created programmatically). How to refer to its properties? For example, I want its text to be equal to Π ΡƒΡ‡ΠΊΠ° .

  • textBoxName.Text = "Π ΡƒΡ‡ΠΊΠ°"; - Dmitry Chistik
  • How to create a TextBox ? - user200141

3 answers 3

First you need to find this control in the collection of parent controls. for example, if you created a textbox and put it into a form:

 string textBoxName = "textBoxName"; var textBox - new TextBox() { Name = textBoxName }; this.Controls.Add(textBox); ... var foundTextBox = this.Controls.OfType<TextBox>() .SingleOrDefault(t => t.Name == textBoxName); if (foundTextBox != null) { // Ρ€Π°Π±ΠΎΡ‚Π°Π΅ΠΌ с тСкстбоксом } else { // Π½Π΅ нашли тСкстбокс с Ρ‚Π°ΠΊΠΈΠΌ ΠΈΠΌΠ΅Π½Π΅ΠΌ } 

    Search by name:

     TextBox tbx = this.Controls.Find("textBoxName", true).FirstOrDefault() as TextBox; tbx.Text = "Π ΡƒΡ‡ΠΊΠ°"; 

    The answer is peeped

       ( Controls["textBoxName"] as TextBox).Text="Π ΡƒΡ‡ΠΊΠ°". 

      suddenly someone come in handy. and thanks to all!