读心术动态加载控件遇到的问题

qin1826681768 2012-04-05 08:15:43
读心术动态加载图片和控件,但是点击button按钮却无法实现图片刷新,再者如何实现是9的倍数的图片加载的都相同?



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _111
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Button myButton = new Button();
myButton.Text = "重试";
myButton.Height = 40;
myButton.Width = 60;
myButton.Top = 15;
myButton.Left = 100;
myButton.Click += new EventHandler(myButton_Click);
this.Controls.Add(myButton);

}
private void myButton_Click(object sender,EventArgs e)
{
Random myRandom = new Random();
int top = 60, left = 60;
int top1 = 100, left1 = 75;
Label[] myLabel = new Label[10];
int s = 1;
PictureBox[] myPicturebox = new PictureBox[10];
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
myPicturebox[j] = new PictureBox();//初始化picturebox的新实例
myPicturebox[j].Image = System.Drawing.Bitmap.FromFile(@"icon\" + myRandom.Next(1, 40) + ".bmp");
myPicturebox[j].Width = 40;
myPicturebox[j].Height = 40;
myPicturebox[j].Top = top;
myPicturebox[j].Left = left;
this.Controls.Add(myPicturebox[j]);
left += 60;
string str = s.ToString();
myLabel[j] = new Label();//初始化类的新实例
myLabel[j].Text = str;
myLabel[j].Width = 40;
myLabel[j].Height = 20;
myLabel[j].Top = top1;
myLabel[j].Left = left1;
this.Controls.Add(myLabel[j]);
left1 += 60;
s = s + 1;
}
top1 += 60;
left1 = 75;
top += 60;
left = 60;

}
}


}
}
...全文
101 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
orochiheart 2012-04-05
  • 打赏
  • 举报
回复
问题还未解决么? Random 声明不应该放在button里面 程序只new一次Random 就够了 new多了会出乱子

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧