#region create textbox
TextBox selfTb=new TextBox();
selfTb.Name = "imgList";
selfTb.Location = new Point(10,260);
selfTb.Size = new Size(300,150);
selfTb.Multiline = true;
this.Controls.Add(selfTb);
using (WebClient client = new WebClient())
{
byte[] imageBytes = client.DownloadData("http://www.hdhcms.com/upfiles/images/20230531/202305312138347358.png");
selfTb.Text = imageBytes.Length.ToString();
using (MemoryStream ms = new MemoryStream(imageBytes))
{
Image image = Image.FromStream(ms);
// 将 image 显示到控件(如 PictureBox)
PictureBox picBox = new PictureBox();
picBox.Location = new Point(320, 260);
picBox.Size = new Size(300,150);
this.Controls.Add(picBox);
picBox.Image = image;
}
}
#endregion
查看更多关于WINFORM通过自建控件并从网上下载图片填充到控件的方法的详细内容...