How to add picturebox to form at runtime using WinForms in C#

1 Answer

0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var picture = new PictureBox
            {
                Name = "pictureBox",
                Size = new Size(250, 200),
                Location = new Point(180, 150),
                Image = Image.FromFile("d:\\test.jpg"),

            };

            this.Controls.Add(picture);
        }
    }
}




/*
run:
 

  
*/

 



answered Jan 25, 2024 by avibootz

Related questions

1 answer 261 views
1 answer 235 views
1 answer 145 views
145 views asked Jan 26, 2024 by avibootz
1 answer 123 views
1 answer 106 views
...