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 7921325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:32:30+00:00 2026-06-03T16:32:30+00:00

I have two forms. Clicking button on form1 opens form2 where user adds details

  • 0

I have two forms. Clicking button on form1 opens form2 where user adds details and this is returned back to form1, information is stored to List and TextBoxes and other elements of interface are created.

I have 5 tabs for different levels but information added is the same.

How can I avoid creating similar code 5 times using

if (level==5) {//do this whole code again}

Example of element added:

int _nextTextBoxTop=15;
List<TextBox> CodesMy = new List<TextBox>();

var code = new TextBox();
CodesMy.Add(code);
code.Location = new Point(12, _nextTextBoxTop);
_nextTextBoxTop += 36;
code.Size = new Size(80, 25);
code.Text = mcode;
tabPageLevel5.Controls.Add.Controls.Add(code); 
  • 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-03T16:32:34+00:00Added an answer on June 3, 2026 at 4:32 pm

    The simplest solution could be to refactor your element creation into a separate function like this:

    CreateControls(TabPage tabPage)
    {
    var code = new TextBox();
    CodesMy.Add(code);
    code.Location = new Point(12, _nextTextBoxTop);
    _nextTextBoxTop += 36;
    code.Size = new Size(80, 25);
    code.Text = mcode;
    tabPage.Controls.Add.Controls.Add(code);     
    }
    

    Your client code would then look like:

    if (level==5) {CreateControls(tabPageLevel5);}
    

    A simpler way than dynamically adding controls could be to create a user control that is used on each of your tab pages.

    Even if you need to add controls dynamically you could still do it with a user control and clone it each time per each additional tab page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two forms, one with a radio button that users must select to
I have two forms. The first form is the mainForm, this never goes anywhere.
I have two forms. First one is to decide button numbers by using jslider.
in my project i have two forms ,when i clicked show form 2 button
I have two forms. First one is to decide numbers of button by using
I have Form1.cs which has two buttons say ADD and EDIT. Clicking ADD shows
I have a form with two UITextFields and a button. The user enters values
I have two buttons on my web form. When clicking on the first button,
I have two forms on one page and want to have the input boxes
I have two forms on my website, and I use jQuery to submit them,

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.