动态加载图片Text
for (int i = 0; i < length; i++) { AddControl(url, i, text); i = i + 1; } /// <summary> /// 动态加载图片Text /// </summary> /// <param name="IUrl">图片链接</param> /// <param name="i"></param> /// <param name="text">文本信息</param> private void AddControl(string IUrl,int i,string text) { string Img = "IMg"; PictureBox IPB = new PictureBox(); IPB.Height = 200; IPB.Width = 250; IPB.SizeMode = PictureBoxSizeMode.StretchImage;//让图片大小刚好 IPB.BackgroundImageLayout = ImageLayout.Stretch;// IPB.Name = Img + i; IPB.Location = new Point(12, 12 + i * 200);//图片位置 try { //图片链接需要验证登录 WebRequest webreq = System.Net.WebRequest.Create(IUrl); NetworkCredential myCred = new NetworkCredential("用户名", "密码"); webreq.Credentials = myCred; WebResponse webres = webreq.GetResponse(); using (Stream stream = webres.GetResponseStream()) { IPB.Image = Image.FromStream(stream); } this.panel1.Controls.Add(IPB); } catch (Exception e) { MessageBox.Show("链接错误"); return; } string Txt = "ITXT"; TextBox txt = new TextBox(); txt.Height = 200; txt.Width = 250; txt.Multiline = true;//多行文本框 txt.Name = Txt + i; txt.Text =text; txt.ScrollBars = ScrollBars.Vertical;//文本框的滚动条 txt.Location = new Point(270, 12 + i * 200); this.panel1.Controls.Add(txt); }