2014-01-29 39 views
0

我已经浏览了这里的几篇文章,并且没有找到我找到的解决方案。我尝试从窗体a传递一个对象到窗体b,当你点击一个菜单项时,它给了我错误:不一致性可访问性:参数类型

错误1不一致的可访问性:参数类型'WindowsFormsApplication1.character'比方法'WindowsFormsApplication1.CharBuilder.CharBuilder(WindowsFormsApplication1.character)'

这里为发送形式:

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

namespace WindowsFormsApplication1 
{ 
    public partial class GVL4 : Form 
    { 
     public GVL4() 
     { 
      InitializeComponent(); 
     } 

     public void mNewGame_Click(object sender, EventArgs e) 
     { 
      character MyCharacter = new character(); 

      MyCharacter.SetIsNew(); 

      CharBuilder NewCharacter = new CharBuilder(MyCharacter); 

      NewCharacter.Show(); 
     } 
    } 
} 

和接收形式:

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

namespace WindowsFormsApplication1 
{ 
    public partial class CharBuilder : Form 
    { 
     character Char = new character(); 

     public CharBuilder() 
     { 
      InitializeComponent(); 
     } 

     //Overloaded Constructor 
     public CharBuilder(character cChar) 
     { 
      Char = cChar; 
     } 

     private void txtSect_TextChanged(object sender, EventArgs e) 
     { 

     } 

     private void btnSaveID_Click(object sender, EventArgs e) 
     { 
      if (Char.IsNew()) 
      { 
       Char.SaveCharIdentity(txtCharName.Text, txtClan.Text, txtSect.Text, txtNature.Text, txtDemeanor.Text, txtTitle.Text, txtCoterie.Text, txtSire.Text, txtPlayerName.Text, txtCharacterID.Text, txtStatus.Text, Convert.ToInt32(txtUnspentXP.Text), Convert.ToInt32(txtEarnedXP.Text), Convert.ToInt32(txtGeneration.Text), Convert.ToInt32(txtBloodPool.Text), cbxNPC.Checked); 
      } 

      txtTestBox.Text = Char.ToString(); 
     } 

     public void CharBuilder_Load(object sender, EventArgs e) 
     { 

     } 

    } 
} 

的错误是在重载(公共CharBuilder(字符CCHAR))

+0

发布定义您的角色类的代码,这是问题的可能来源。 –

回答

0

这意味着你character类比public少,比如您的公共方法。您需要确保访问修饰符相同。我不确定你的班级设计,所以不知道最佳路线是什么,但如果没有人将你的代码作为图书馆使用,只需要公开角色类。

+0

BAH。当然。我正在看表格代码而不是我的角色班。它没有明确的公开。感谢您的帮助! –

0

你没有发布你的角色类的代码,但它听起来像这个类被标记为public以外的东西,这就是你看到这个错误的原因。将您的character类的声明更改为public,它将起作用。

1

character类在哪里定义?我嫌犯这是GVL4里面的私人课程?什么错误是告诉你的是,即使你要传递的character一个实例CharBuilderCharBuilder实际上不知道有什么一个对象character任何方式。它接收一个对象,但它没有定义该对象的类。

确保character类对这两种形式都是已知的。我想应该只是在项目中的其他地方定义的一个单独的类,可能是公开的或内部的,而不是任何特定形式的内部。

侧注意:您的代码非常难以阅读,因为您没有遵循C#约定。类/类型名称应该以大写字母开头,局部变量名称应该以小写字母开头。

+0

几个小时前我刚刚开始在C#中编写代码,这些约定我一无所知。谢谢你的信息,但我会确保查找它们并尝试合并它们。 –

相关问题