标题:这段觉得写得有点啰嗦,请帮忙修改修改
只看楼主
jack_xu2046
Rank: 2
等 级:论坛游民
帖 子:72
专家分:11
注 册:2008-10-1
结帖率:81.82%
已结贴  问题点数:10 回复次数:7 
这段觉得写得有点啰嗦,请帮忙修改修改
            for (int i = 0; i < 5; i++)
            {
                tmp = ra.Next(minValue, maxValue); //随机取数
                arrNum[i] = getNum(arrNum, tmp, minValue, maxValue, ra); //取出值赋到数组中
               
            }

            MemoryStream ms0 = new MemoryStream(FromDataBase(arrNum[0]));
            MemoryStream ms1 = new MemoryStream(FromDataBase(arrNum[1]));
            MemoryStream ms2 = new MemoryStream(FromDataBase(arrNum[2]));
            MemoryStream ms3 = new MemoryStream(FromDataBase(arrNum[3]));
            MemoryStream ms4 = new MemoryStream(FromDataBase(arrNum[4]));
            pictureBox1.Image = Image.FromStream(ms0, true);
            label1.Text = GetNameFromDateBase(arrNum[0]);
            pictureBox2.Image = Image.FromStream(ms1, true);
            label2.Text = GetNameFromDateBase(arrNum[1]);
            pictureBox3.Image = Image.FromStream(ms2, true);
            label3.Text = GetNameFromDateBase(arrNum[2]);
            pictureBox4.Image = Image.FromStream(ms3, true);
            label4.Text = GetNameFromDateBase(arrNum[3]);
            pictureBox5.Image = Image.FromStream(ms4, true);
            label5.Text = GetNameFromDateBase(arrNum[4]);
搜索更多相关主题的帖子: 啰嗦 
2010-10-10 12:25
jack_xu2046
Rank: 2
等 级:论坛游民
帖 子:72
专家分:11
注 册:2008-10-1
得分:0 
回复 楼主 jack_xu2046
            for (int i = 0; i < 5; i++)
            {
                tmp = ra.Next(minValue, maxValue); //随机取数
                arrNum[i] = getNum(arrNum, tmp, minValue, maxValue, ra); //取出值赋到数组中
                ms[i] = new MemoryStream(FromDataBase(arrNum[i]));
            }
            pictureBox1.Image = Image.FromStream(ms[0], true);
            label1.Text = GetNameFromDateBase(arrNum[0]);
            pictureBox2.Image = Image.FromStream(ms[1], true);
            label2.Text = GetNameFromDateBase(arrNum[1]);
            pictureBox3.Image = Image.FromStream(ms[2], true);
            label3.Text = GetNameFromDateBase(arrNum[2]);
            pictureBox4.Image = Image.FromStream(ms[3], true);
            label4.Text = GetNameFromDateBase(arrNum[3]);
            pictureBox5.Image = Image.FromStream(ms[4], true);
            label5.Text = GetNameFromDateBase(arrNum[4]);
        }
修改了一下,如何将picturebox与label放到循环中?

菜鸟中的菜鸟
2010-10-10 12:52
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
得分:0 
把picturebox和label都定义为数组就比较适合放在循环中了?!
2010-10-10 19:55
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2545
专家分:9359
注 册:2007-11-3
得分:4 
回复 楼主 jack_xu2046
            MemoryStream ms;
            PictureBox[] _pictureBox= new PictureBox[5] {PictureBox1,PictureBox2,PictureBox3,PictureBox4,PictureBox5 };
            Label[] _label=new Label[5]{Label1,Label2,Label3,Label4,Label5};
            try
            {
                for (int i = 0; i < 5; i++)
               {
                tmp = ra.Next(minValue, maxValue); //随机取数
                arrNum[i] = getNum(arrNum, tmp, minValue, maxValue, ra); //取出值赋到数组中
                           ms=new MemoryStream(FromDataBase(arrNum[i]));
                           pictureBox[i].Image =Image.FromStream(ms, true);
                           label[i].Text=GetNameFromDateBase(arrNum[i]);

               }//for(i)结束
            }
            catch
            {
            }
            final
            {
            ms=null;
            }

[ 本帖最后由 wangnannan 于 2010-10-11 10:39 编辑 ]

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2010-10-11 10:35
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:0 
反射.   

飘过~~
2010-10-11 12:38
jack_xu2046
Rank: 2
等 级:论坛游民
帖 子:72
专家分:11
注 册:2008-10-1
得分:0 
回复 4楼 wangnannan
这方法不错

菜鸟中的菜鸟
2010-10-11 17:42
jack_xu2046
Rank: 2
等 级:论坛游民
帖 子:72
专家分:11
注 册:2008-10-1
得分:0 
以下是引用bygg在2010-10-11 12:38:30的发言:

反射.   
具体咋实现,可以演示一下吗

菜鸟中的菜鸟
2010-10-11 17:44
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:6 
程序代码:
 for (int i = 0; i < 5; i++)
{
    tmp = ra.Next(minValue, maxValue); //随机取数
    arrNum[i] = getNum(arrNum, tmp, minValue, maxValue, ra); //取出值赋到数组中
    ms[i] = new MemoryStream(FromDataBase(arrNum[i]));

    System.Reflection.FieldInfo   fieldInfo =   this.GetType().GetField( "pictureBox" + (i+1).ToString());
    pictureBox picbox =   (pictureBox )fieldInfo.GetValue(this);
    picbox .Image = Image.FromStream(ms[i], true);
   
    System.Reflection.FieldInfo   fieldInfo =   this.GetType().GetField( "label" + (i+1).ToString());
    Label lb=   (Label )fieldInfo.GetValue(this);
    lb.Text = GetNameFromDateBase(arrNum[i]);
}

大概是这样的,没测试仪,是用的记事本写的.

飘过~~
2010-10-11 22:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-322435-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.167568 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved