How to programmatically set the Image source

后端 未结 6 1088
囚心锁ツ
囚心锁ツ 2021-02-01 14:16

When the Image\'s Source property is set the following way, the picture is taken from /Images/down.png.

How would I do the same thing programmatically?

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 14:39

    try this

    PictureBox picture = new PictureBox
            {
                Name = "pictureBox",
                Size = new Size(100, 50),
                Location = new Point(14, 17),
                Image = Image.FromFile(@"c:\Images\test.jpg"),
                SizeMode = PictureBoxSizeMode.CenterImage
            };
    p.Controls.Add(picture);
    

提交回复
热议问题