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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:47:21+00:00 2026-05-13T14:47:21+00:00

I have to develop Windows C# application, using Visual Studio 2008. It have dynamical

  • 0

I have to develop Windows C# application, using Visual Studio 2008. It have dynamical to create pictureboxes, to add image in it, and to move picturebox to some X position.

So, I have windows form with next components:

  1. button, with title “Add new”
  2. Combobox
  3. Text Field
  4. another button, with title “Set position”.

Also, I have one folder with several images (png files) in it.

So, when I click on first button it have to create new PictureBox, and to add name of Picturebox into ComboBox.

After that, I can choose one PictureBox from it’s list in combobox, and to move it to X position I entered into TextBox.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DynamicComponents
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int imgCounter = 0;


        /*
         * Create pictureboxes and add images
         */ 
        private void button1_Click(object sender, EventArgs e)
        {
            PictureBox pb = new PictureBox();
            pb.Name = "PictureBox" + (++imgCounter);
            pb.Size = new Size(100, 100);
            pb.Image = Image.FromFile(@"C:\slike\" + imgCounter.ToString() + ".png");
            this.Controls.Add(pb);
            comboBox1.Items.Add(pb.Name);
        }


        /*
         * Move PictureBox on X position I entered into textfield
         * */
        private void button2_Click(object sender, EventArgs e)
        {
            // help!!!
        }
    }
}
  • 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-13T14:47:22+00:00Added an answer on May 13, 2026 at 2:47 pm

    You have already (successfully it seems) managed to dynamically create new PictureBox controls, add them to the form and also show their name in the ComboBox.

    When you click the button, you will somehow need to “navigate” from the selected item in the ComboBox to a PictureBox. One simple way of achieving this is to use the fact that the list in a ComboBox takes any object, not only strings. So, instead of adding pb.Name to the ComboBox, you can add pb itself. This will create one small problem though; instead of the name of the picture box, the combo box will now show System.Windows.Forms.PictureBox. This can be fixed by setting the DisplayMember property of the ComboBox (this property tells the ComboBox which property value to fetch from each object and use for display):

    So, you could set the DisplayMember property in the constructor of Form1:

    public Form1()
    {
        InitializeComponent();
        comboBox1.DisplayMember = "Name"; // use the Name property from items 
                                          // in the list when displaying them
    }
    

    Then, when creating the PictureBox controls, add them to the ComboBox:

    comboBox1.Items.Add(pb);
    

    Now you can easily pick up the PictureBox reference from the ComboBox in button2_Click:

    private void button2_Click(object sender, EventArgs e)
    {
        PictureBox selectedPictureBox = comboBox1.SelectedItem as PictureBox;
        if (selectedPictureBox != null)
        {
             // use selectedPictureBox to set the appropriate property values
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 377k
  • Answers 377k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Give a look to the following article published just a… May 14, 2026 at 8:48 pm
  • Editorial Team
    Editorial Team added an answer Firstly, what you want is malformed HTML. jQuery is going… May 14, 2026 at 8:47 pm
  • Editorial Team
    Editorial Team added an answer It is odd in my view that Xaml can't parse… May 14, 2026 at 8:47 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.