Form1中的代码是:
public int[] recordNumber()

int[] a=new int [9];
for(int i=0;i<9;i++)
{
a[i]=0;
}
if(checkBox1.Checked&&comboBox1.SelectedIndex!=-1)
{
a[0]++;
a[1]=comboBox1.SelectedIndex+1;
}
return a;
}
Form2中代码是:
public void check()
{
Form1 abc=new Form1();
int[] a=abc.recordNumber();
listBox1.Items.Clear();
listBox2.Items.Clear();
string[] type=new string[6];
string[] animals= new string[8];
string[] recode = new string[16];
for (int j = 0; j < 16; j++)
{
recode[j] = null;
}
type[0] = null;
type[1]="哺乳类";
type[2]="鸟类";
type[3]="肉食类";
type[4]="有碲类";
type[5]="碲类";
animals[0]=null;
animals[1]="金钱豹";
animals[2]="老虎";
animals[3]="长颈鹿";
animals[4]="斑马";
animals[5]="鸵鸟";
animals[6]="企鹅";
animals[7]="信天翁";
if (a[0] == 0)
{
listBox1.Items.Add("请先输入你想知道的动物的几个特征!!");
}
......
但是数组就是米有传过去啊

解决方案 »

  1.   

    没传过去?a[0]全都为0?应该是
    if(checkBox1.Checked&&comboBox1.SelectedIndex!=-1)
    {
    a[0]++;
    a[1]=comboBox1.SelectedIndex+1;
    }
    没执行
      

  2.   

    if(checkBox1.Checked&&comboBox1.SelectedIndex!=-1)
    {
    a[0]++;
    a[1]=comboBox1.SelectedIndex+1;
    }
    我估计可能是这里有问题吧因为你都没有选啊这个语句快应该是不会执行的啊
      

  3.   

    我觉的你应该先new 并 show Form1 然后通过事件来调用你的public int[] recordNumber()
    方法
    之后再new 和 show Form2并把form1 的数组通过重载一个form2的构造方法来传递到form2中
    这是我的思路可能比较笨的一个方法但应该是有效的吧.
      

  4.   

    Form1 abc=new Form1();
    int[] a=abc.recordNumber();这里执行的结果, a里面的肯定全部是0你应该把Form1作为一个parameter放到Form2的Constructor里面, 把它作为一个全局变量Form2:private Form1 abc;public Form2(Form1 frm)
    {
    //some other code
    this.abc = frm;
    }public void check()
    {
    //Form1 abc=new Form1();
              //当Form1 abc里面的CheckBox或ComboBox有选中时, a得到的就不会全部是0
    int[] a=abc.recordNumber();
    listBox1.Items.Clear();
    listBox2.Items.Clear();
    string[] type=new string[6];
    string[] animals= new string[8];
    string[] recode = new string[16];
    for (int j = 0; j < 16; j++)
    {
    recode[j] = null;
    }
    type[0] = null;
    type[1]="哺乳类";
    type[2]="鸟类";
    type[3]="肉食类";
    type[4]="有碲类";
    type[5]="碲类";
    animals[0]=null;
    animals[1]="金钱豹";
    animals[2]="老虎";
    animals[3]="长颈鹿";
    animals[4]="斑马";
    animals[5]="鸵鸟";
    animals[6]="企鹅";
    animals[7]="信天翁";
    if (a[0] == 0)
    {
    listBox1.Items.Add("请先输入你想知道的动物的几个特征!!");
    }
      

  5.   

    if(checkBox1.Checked&&comboBox1.SelectedIndex!=-1)
    {
    a[0]++;
    a[1]=comboBox1.SelectedIndex+1;
    }问题出在这里哈~~
      

  6.   

    晕。问题不在Form1里头的。我测试了。 那是正确的。只是传不到2这里来。还有LeoMaya(我是L.W, 这是我的故事) 你的方法不可以实现出来。还是和没有改我的代码时候的错误一样
      

  7.   

    anyway, 问题不在于你的code或者我的code的什么不妥, 只是, 你的programm的behavior, 如果任何情况下, 你都想在CheckBox/ComboBox没作什么动作的时候让a[]里面有非0值, 你觉得有可能么?
    我帮你改进后的code, 是想你可以自由的在CheckBox/ComboBox被处理过后再调用Check(), 不然, 按你原来的code, a[]里面永远都只会是0