0

I'm trying to write some text into a textbox whose name is based on num1 and num2 as mentioned in the code. so, if num1 and num2 are 0, 0 then the text should be written to a textbox with name 'textbox00' similarly if num1 and num2 are 1, 1 then the text should be written to 'textbox11'. Is this possible?

int num1;
int num2;
if (num1 == 0 && num2 == 0)
{
  //Write some text into textBox with name $"textbox{num1}{num2}"
}

Thank you!

Manoj_S
  • 13
  • 1
  • NameOfYourTextBox.Text = "your text "; – Damien PAYET Jun 15 '21 at 12:06
  • Does this answer your question? [Find control by name from Windows Forms controls](https://stackoverflow.com/questions/3898588/find-control-by-name-from-windows-forms-controls) and [Get all controls with names that start with specific string](https://stackoverflow.com/questions/29877904/get-all-controls-with-names-that-start-with-specific-string) –  Jun 15 '21 at 12:07
  • 1
    Thanks for the link. This looks similar to my question. – Manoj_S Jun 15 '21 at 12:10

1 Answers1

-2

what i understand you want to select specific textbox based on num1 & num2 values

you can do it by using the below code

  if (num1 == 0 && num2 == 0)
    {
        var textbox = Controls.Find("textbox" + num1+ num2  , true).FirstOrDefault(); 
     
    if (textbox != null) 
    { 
        textbox.Text= "Your text"; 
    }   
}
Tahir Rehman
  • 332
  • 2
  • 9