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 Π ΡΡΠΊΠ° .
3 answers
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 = "Π ΡΡΠΊΠ°"; |
( Controls["textBoxName"] as TextBox).Text="Π ΡΡΠΊΠ°". suddenly someone come in handy. and thanks to all!
|
textBoxName.Text = "Π ΡΡΠΊΠ°";- Dmitry ChistikTextBox? - user200141