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

  • Home
  • SEARCH
  • 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 7279071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:58:18+00:00 2026-05-28T22:58:18+00:00

I am creating a form, and on load it gets all images from my

  • 0

I am creating a form, and on load it gets all images from my resources folder and for each file creates a new button, sets the buttons background image to that image and adds that button to the form, but it is only displaying 1 button and there are 36 files in the resources folder.

My code is as follows:

ResourceSet resourceSet = Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
foreach (DictionaryEntry entry in resourceSet)
{
    object resource = entry.Value;
    Button b = new Button();
    b.BackgroundImage = (Image)resource;
    b.BackgroundImageLayout = ImageLayout.Stretch;
    b.Height = 64;
    b.Width = 64;
    this.Controls.Add(b);
}

Please assist on what I am doing wrong.

  • 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-05-28T22:58:19+00:00Added an answer on May 28, 2026 at 10:58 pm

    My guess is that the code is indeed adding all the buttons but that they are all on top of each other. Each button will have a default value for Left and Top and those default values will be the same for each button. Since the buttons all have the same size, only the top button is visible.

    Solve the problem by setting the Left and Top properties for each button. Obviously each different button needs to have a different value for Left and Top.


    To answer the question you ask in a comment, you could use code along these lines:

    const int buttonSize = 64;
    int left = 0;
    int top = 0;
    foreach (DictionaryEntry entry in resourceSet)
    {
        object resource = entry.Value;
        Button b = new Button();
        b.BackgroundImage = (Image)resource;
        b.BackgroundImageLayout = ImageLayout.Stretch;
        b.Bounds = Rectangle(left, top, buttonSize, buttonSize);
        this.Controls.Add(b);
    
        // prepare for next iteration
        left += buttonSize;
        if (left+buttonSize>this.ClientSize.Width)
        {
            left = 0;
            top += 64;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a form dynamically from the fields returned from server using json
After creating a new form, I usually perform this ritual: Change the name into
I am creating an HTML form with some radio button options. I'd like to
On my Form Load event I am creating a bitmap using System.Drawing classes, and
I am creating a simple form based message display system, each message is a
I'm creating backgroundworker not in my windows form but in the class file (BusinessLogic)
I get a script that creates a form with an input file after clicking
I have several questions regarding CI application design. Q. When creating a new form
Eariler I happily used the following code for creating form elements (inside Zend_Form descendant):
I'm creating a form using the Content Construction Kit (CCK) in Drupal5. I've added

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.