0

我制作了一个类似于 wiki 的程序,但在一个程序中。我添加了很多图片框,并且我有 3 个过滤器来对这些图片框进行排序:角色、攻击类型和名称。我想做的是,例如,如果您选择攻击类型 RANGED,它会禁用其他具有与 RANGED 不同攻击类型的图片框。

我试过用计时器比较每个英雄(我为它制作了不同的类),但我不知道该怎么做。

我也试过这个

if(comboBox1.Text == "RANGED") { //do stuff }

但是我不知道如何访问我创建的数组中的所有英雄,并检查他们是否有 atkType = RANGED。

我的 Hero.cs 类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace WindowsFormsApplication1
{
    public struct Hero
    {
        public string Name;
        public string Role; /* carry, disabler, lane support, initiator, jungler, support, durable, nuker, pusher, escape */
        public string atkType; /* melee or ranged */
        public string Type; /* strength, agility or intelligence */
        public string imgName;

        public Hero(string name, string role, string atktype, string type, string imgname)
        {
            Name = name;
            Role = role;
            atkType = atktype;
            Type = type;
            imgName = imgname;
        }

        public static Hero[] heroes = new Hero[] { 
            new Hero() {Name = "test", Role = "", atkType = "Melee", Type = "Strength", imgName = "test" }
        };
    }
}

我已经设法让过滤器工作,但现在,只有一个问题:我无法处理(图像不会卸载)当前加载的图像,也无法加载新的图像。我尝试了什么:

 if (melee == false && ranged == false)
        {
            for (int i = 0; i < Hero.heroes.Length; i++)
            {
                imgs[i].Load("http://cdn.dota2.com/apps/dota2/images/heroes/" + Hero.heroes[i].imgName + "_sb.png");
                comboBox3.Items.Add(Hero.heroes[i].Name);
                //imgs[i].MouseHover += displayInfo(i);
            }

        }
        if (ranged == true)
        {
            for (int i = 0; i < Hero.heroes.Length && Hero.heroes[i].atkType.Contains("Ranged"); i++)
            {
                imgs[i].Image.Dispose();
                imgs[i].Load("http://cdn.dota2.com/apps/dota2/images/heroes/" + Hero.heroes[i].imgName + "_sb.png");
            }
        }
4

1 回答 1

0

代码可能是这样的:

if(cmb.text=="goofy")
    //Code
else if(cmb.text=="mars")
   //Other code
else 
   //BLA BLA
于 2013-10-08T19:27:45.827 回答