动态加载图片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);
        }                                        

 

转载于:https://www.cnblogs.com/doting/p/7347357.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值