private void Form1_Load(object sender, EventArgs e)
{
//创建数组。数量为imagelist列表的总数
PictureBox[] stephy = new PictureBox[imageList1.Images.Count + 1];
//创建随机数
ArrayList al = new ArrayList();
while (al.Count <= 4)
{
Random rnd = new Random();
int x= rnd.Next(5);
if (!al.Contains(x))
{
al.Add(x);
}
}
//随机分配图片
for(int i=0;i<=4;i++)
{
stephy[i] = new PictureBox();
System.Drawing.Image image = imageList1.Images[int.Parse(al[i].ToString())];
stephy[i].Image =image;
int H1 = 0;
int W1 = 0; switch (i)
{
case 0:
H1 = 0;
W1 = 0 * image.Size.Width;
break;
case 1:
H1 = 0;
W1 = 1 * image.Size.Width; ;
break;
case 2:
H1 = 120;
W1 = 0 * image.Size.Width;
break;
case 3:
H1 = 120;
W1 = 1 * image.Size.Width;
break; case 4:
H1 = 240;
W1 = 0 * image.Size.Width;
break;
}
stephy[i].Location = new System.Drawing.Point(W1, H1);
stephy[i].Size = new System.Drawing.Size(184, 120);
stephy[i].Tag = i;
this.panel1.Controls.Add(stephy[i]);
}
PictureBox mlgb=new PictureBox();
mlgb.Image=null;
mlgb.Tag = 999;
this.panel1.Controls.Add(mlgb);
stephy[0].Click += new EventHandler(stephy_Click);
stephy[1].Click += new EventHandler(stephy1_Click);
stephy[4].Click += new EventHandler(stephy4_Click);
}
这是个拼图游戏。现在可以对单个事件控制了。但是怎么找到stephy1.stephy2 这些控件。我要实现。单击stephy1 判断旁边2个 stephy2 stephy3 是否为空。为空的把自己的图像复制给它。然后清空自己。
就像这样
private void pictureBox1_Click(object sender, EventArgs e)
{
if (pictureBox2.Image ==null)
{
pictureBox2.Image = pictureBox2.Image;
pictureBox1.Image = null;
}
} 各位高手帮帮忙。先谢了
{
//创建数组。数量为imagelist列表的总数
PictureBox[] stephy = new PictureBox[imageList1.Images.Count + 1];
//创建随机数
ArrayList al = new ArrayList();
while (al.Count <= 4)
{
Random rnd = new Random();
int x= rnd.Next(5);
if (!al.Contains(x))
{
al.Add(x);
}
}
//随机分配图片
for(int i=0;i<=4;i++)
{
stephy[i] = new PictureBox();
System.Drawing.Image image = imageList1.Images[int.Parse(al[i].ToString())];
stephy[i].Image =image;
int H1 = 0;
int W1 = 0; switch (i)
{
case 0:
H1 = 0;
W1 = 0 * image.Size.Width;
break;
case 1:
H1 = 0;
W1 = 1 * image.Size.Width; ;
break;
case 2:
H1 = 120;
W1 = 0 * image.Size.Width;
break;
case 3:
H1 = 120;
W1 = 1 * image.Size.Width;
break; case 4:
H1 = 240;
W1 = 0 * image.Size.Width;
break;
}
stephy[i].Location = new System.Drawing.Point(W1, H1);
stephy[i].Size = new System.Drawing.Size(184, 120);
stephy[i].Tag = i;
this.panel1.Controls.Add(stephy[i]);
}
PictureBox mlgb=new PictureBox();
mlgb.Image=null;
mlgb.Tag = 999;
this.panel1.Controls.Add(mlgb);
stephy[0].Click += new EventHandler(stephy_Click);
stephy[1].Click += new EventHandler(stephy1_Click);
stephy[4].Click += new EventHandler(stephy4_Click);
}
这是个拼图游戏。现在可以对单个事件控制了。但是怎么找到stephy1.stephy2 这些控件。我要实现。单击stephy1 判断旁边2个 stephy2 stephy3 是否为空。为空的把自己的图像复制给它。然后清空自己。
就像这样
private void pictureBox1_Click(object sender, EventArgs e)
{
if (pictureBox2.Image ==null)
{
pictureBox2.Image = pictureBox2.Image;
pictureBox1.Image = null;
}
} 各位高手帮帮忙。先谢了
解决方案 »
- 我又来提问了 关于XML node的问题
- 用C# 做串口通信 serialprot
- 【WPF】怎样实现Drag&Drop,比如从左边的ListBox里拖放一项到右边某个控件时,把拖动项的Text显示在某一控件上。
- 求C#的CRC-8校验码函数
- C#窗帘效果问题
- 关于ListBox 删除数据的问题 求助!!!
- 怎样实时读取外部硬件I/O的状态?
- 我用C#按照书上的例子编了个C# Web应用程序,我在该WEB窗体上添加了一个Calendar控件(此控件是从工具箱中的Web Forms选项卡中得到的),
- 请问如何将tabControl倒过来.就像.net 中的output窗体一样。
- 我的中文在ASP.NET中显示成问号,是字符集的问题吧,请问怎样解决?
- winform 时间比较
- c#dataGridView包含combobox的回车相应问题
然后根据stephy 的索引不就好了吗 起码我是这么做的