Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8318991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:10:07+00:00 2026-06-08T22:10:07+00:00

Has C# indexed control arrays or not? I would like to put a button

  • 0

Has C# indexed control arrays or not? I would like to put a “button array” for example with 5 buttons which use just one event handler which handles the index of all this 5 controls (like VB6 does). Else I have to write for each of these 5 buttons one extra event handler. And if I have 100 buttons, I need 100 event handlers? I mean something like that:

TextBox1[i].Text="Example";

It could make coding definitely easier for me to work with control arrays. Now I have seen, that C# at least has no visible array functionality on user controls and no “index” property on the user controls. So I guess C# has no control arrays, or I must each element call by known name.

Instead of giving 100 TextBoxes in a for loop 100 incrementing values, I have to write:

TextBox1.Text = Value1;
TextBox2.Text = Value2;
...
...
TextBox100.Text = Value100;

A lot of more work + all these 100 event handlers each for one additional TextBox extra.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:10:09+00:00Added an answer on June 8, 2026 at 10:10 pm

    As I mentioned in comment to a solution by HatSoft, C# Winforms does not allow you to create control arrays like old VB6 allowed us. The nearest I think we can get to is what HatSoft and Bert Evans in their posts have shown.

    One thing that I hope would satisfy your requirement is the event handler, you get a common event handler and in the event handler when you typecast the “sender” you get the control directly just like you would in VB6

    C#

    TextBox textBox = sender as TextBox;
    

    VB6

    TextBox textBox = TextBox1[i];
    

    So the only trouble you might have is wiring those 100 TextBoxes to a single event handler, if you are not creating the controls dynamically through code rather creating it manually at design time then all one can suggest is group them in a container like say Panel. Then on Form Load wire them all up to a single event handler like this:

    foreach (Control control in myTextBoxPanel.Controls)
    {
        if(control is TextBox)
             control.TextChanged += new EventHandler(control_TextChanged);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Google has indexed certain pages in my website that I wouldn't like users to
I'm finding not being able to use control statements in unit tests very tedious
Not sure how it happened, but Google has indexed my site both by IP
I've come across the excellent PDF Library code SynPDF and would like to use
I have recently indexed my website. Google has indexed the main site as: www.site.com/?ref=old
We have a dev server that has managed to become indexed by Google. Page
Has anyone used Hazelcast (preferably 2.1) with play framework 2.0/2.1 (not 1.2+)? I am
I'm looking for a STL container that works like std::multimap, but has constant access
I have a form, myForm, which has KeyPreview set to true. The idea is
I have a Flex3 project with 2 HorizontalList controls; one of which has drag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.