我想创建一个表单,可以在其中编辑类TagHandler
的字段。
因此,我决定将参数传递给表单的构造函数TagHandler tag
,其中tag
-是我要编辑的标签。在我的表单中,我有一个字段tag
,我可以对其进行编辑,然后获取其数据。
例如在我的主窗体中,我有一个使用MouseDoubleClick
方法的列表框
void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int index = listBox1.SelectedIndex;
TagHandler tg = listData[index];
EditTag edit = new EditTag(tg);
if (edit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
listData[index] = edit.Tag as TagHandler;
}
}
其中
EditTag
是一种形式public partial class EditTag : Form
{
public TagHandler tag { set; get; }
public EditTag(TagHandler tag)
{
InitializeComponent();
this.CenterToParent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.tag = tag;
this.label2.Text = tag.Tag;
}
private void button1_Click(object sender, EventArgs e)
{
tag.Data = richTextBox1.Text;
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
但是我有这样的错误
可访问性不一致:属性类型“ XmlMissionEditor.TagHandler”的访问权限比属性“ XmlMissionEditor.EditTag.tag”的访问权限少
可访问性不一致:参数类型'XmlMissionEditor.TagHandler'的可访问性比方法'XmlMissionEditor.EditTag.EditTag(XmlMissionEditor.TagHandler)'
有什么问题?我什至将
tag
字段设置为public
,但它仍然显示相同的错误。我的班级
TagHandler
看起来像这样[Serializable]
class TagHandler
{
private string data;
private string tag;
private Color color;
private List<AttributeHandler> attributes;
public TagHandler(string tag, bool close)
{
attributes = new List<AttributeHandler>();
if (close)
{
string s = "/" + tag;
this.tag = s;
}
else
{
this.tag = tag;
}
}
public string Tag
{
get { return tag; }
set { tag = value; }
}
public string Data
{
get { return data; }
set { data = value; }
}
...other methods
}
最佳答案
这些是问题:
public TagHandler tag { set; get; }
public EditTag(TagHandler tag)
后者是公共类中的公共方法。因此,它的所有参数及其返回类型也应该是公共的-否则,您说的是“可以调用此函数,但您不知道要使用其调用的类型”(或者返回的是什么,如果返回的话)类型不是公共的,同样,属性的类型也必须是公共的。
将构造函数和属性设为内部,或者将
TagHandler
类型设为公共。