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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:38:35+00:00 2026-06-03T22:38:35+00:00

Background: For the most part, I’m self taught in C#, so I apologize if

  • 0

Background: For the most part, I’m self taught in C#, so I apologize if this is some simple-minded problem. I am creating something to the effect of a mailing list (each object has name, address, contact info, etc) and will be printing out in labels (there will be two colums and four rows per printed page). I have the list in formMain where you can add, edit and delete individual labels and I have a form printPreview(one) for individual entries selected from the list.

The problem: I’m trying to create a print preview form for the whole list; generating a group box (containing a text box and picture box) for each object from the list – that way I’ll have exactly the number of labels as objects – then fill each box with the content respective to each object on the list.
Each group box, text box and picture box are specific sizes and will be spaced so there’s room between each label. So here’s the pseudo code I’m trying to make happen;

//box[num] contains
//text box at location(6,19)
//picture box at location(222,19)

int locX = 0;
int locY = 0;
listObj = list.first;

for (int i = 0; i < list.count; i++)
{
  //create box[i] at location (locX, locY);
   box[i].textbox.text = listObj.text;
   box[i].picturebox.image = Image.FromFile(listObj.photoLocation);
   if(i%2)
   {
       locX+=400;
    }
   else
   {
       locY+=248;
       locX=0;
    }
   listObj = listObj.next;
}

Now, I know there’s a lot of holes in there, but I just need the basic: how do I get my program to create new group boxes in a form equal to the number of objects in my list?

  • 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-03T22:38:36+00:00Added an answer on June 3, 2026 at 10:38 pm

    Your wording is throwing me a little, but I’m going to try and address this. Forgive me if I’m way off.

    To answer the direct, simple answer; adding a groupbox to a form:

    
    GroupBox groupbox1 = new System.Windows.Forms.GroupBox();
    groupbox1.Location = new System.Drawing.Point(x, y);
    form1.Controls.Add(groupbox1);
    
    Textbox textbox = new System.Windows.Forms.Textbox();
    textbox.Location = new System.Drawing.Point(x2, y2);
    groupbox1.Controls.Add(textbox);
    
    // same for picturebox, where x/x2 and y/y2 are your calculated 
    // placements of the controls
    
    

    Making an equal number of them as the number in your list will require some sort of iteration; you’ll have to either make a List and add them, or just for(i=0 -> N) add them. You’ll have to work out the math on the placement though for each one, depending on how you want it to look (margins, padding, size, etc.)

    Now, in a little more detail:

    I think a TableLayoutPanel or FlowLayoutPanel would be a very good fit for what you’re doing. Drop a Table/FlowLayoutPanel onto your dialog, and then in your code programmatically make your groupboxes and add them to the table. Both are excellent at handling control positioning for you. If you size the table before hand, you shouldn’t need to worry about finding the locations, you can just add them in one at a time and the layoutpanel handle the rest.

    
    foreach(GroupBox groupbox in labelGroupBoxes)
    {
        tableLayoutPanel.Controls.Add(groupbox);
    }
    

    There are a couple of things you'll want to look at for this, I think. The FlowlayoutPanel, TableLayoutPanel and the Autosize property of winform controls are a few. Create your new Form, add a layout panel, start creating groupboxes the size of the labels you want, set the row/column sizes of the tablelayoutpanel to AutoSize if you use that one, and start sticking them in.

    Here's a reasonably good video on table layout panel, I can't find the one I was actually looking for...

    http://msdn.microsoft.com/en-us/vstudio/Video/bb798032

    Video on flowlayoutpanel:

    http://msdn.microsoft.com/en-us/vstudio/Video/bb798028

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

Sidebar

Related Questions

i have this jquery crossfade that is working for the most part except it
I apologize i don't have any code to show for this problem. But i
Background I'm trying to implement a simple web server part as a web interface
I have a scroll view with transparent background that covers most of the screen.
Most of my company's web programming background is PHP, so ASP.NET MVC was a
Background I admit, this question stems from an ultimate lack of deep understanding of
Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some
Background, Part 1 I have a form that collects both frequency and duration from
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
Background Information: I'm part of a team of developers that runs a web application

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.