日期:2014-05-18  浏览次数:20888 次

关于C#编写读心术的问题
现在可以把图片和button按钮显示在窗体上了,但是点击按钮只能实现一次加载,再点击图片不能更新,代码如下,请高手帮忙解决。谢谢各位!!!

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);
  //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 < 9; j++)
  // {
  // string str = s.ToString();
  // myLabel[j] = new Label();//初始化类的新实例 
  // myLabel[j].Text = str;
  // myLabel[j].Width = 20;
  // myLabel[j].Height = 20;
  // myLabel[j].Top = top1;
  // myLabel[j].Left = left1;
  // this.Controls.Add(myLabel[j]);
  // left1 += 60;
  // 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;
  // s = s + 1;
  // }
  // top1 += 60;
  // left1 = 75;
  // top += 60;
  // left = 60;

  //}

  }
  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;