Get Name of Multiple TextBoxes Control in C#

This is a simple tutorial in which we are going to get all the name of multiple textboxes in C# using a loop. So, now let's start this tutorial! 1. Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio 2010: Go to File, click New Project, and choose Windows Application. 2. Drag any textbox that you want and only one Button. You must design your interface like this: design 3. Put this code in your button1_click. This will trigger to show the names of the textboxes that you have dragged.
  1. private void Button1_Click(System.Object sender, System.EventArgs e)
  2. {
  3. //create a variable that represents the control.
  4. Control txt = default(Control);
  5. //After that, Loop the control that you have created.
  6. foreach (Control tempLoopVar_txt in this.Controls)
  7. {
  8. //Then, check if the type of the control is a Textbox and if it’s true, then perform the process that puts the name of the TextBox to itself. Do this code inside the Loop.
  9. txt = tempLoopVar_txt;
  10. if (txt.GetType == typeof(TextBox))
  11. {
  12. txt.Text = txt.Name;
  13. }
  14. }
  15. }
Output: output For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment