This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center。
7年前关闭。
我正在处理具有两个窗口的表单应用程序。在主窗口Form1中,我创建了Treatment类的实例。一旦将图像单击到另一个窗口form2,我想传递该实例。到目前为止,我有:
表格1:
并在form2中:
我得到1错误:错误1不一致的可访问性:参数类型'WasteTreatment.Treatment'的访问比方法'WasteTreatment.Form2.Form2(WasteTreatment.Treatment)'少。
有人可以帮我解决这个问题吗?
您可以将
7年前关闭。
我正在处理具有两个窗口的表单应用程序。在主窗口Form1中,我创建了Treatment类的实例。一旦将图像单击到另一个窗口form2,我想传递该实例。到目前为止,我有:
表格1:
public partial class Form1 : Form
{
private Treatment treatment;
//method where i inistantiate the treatment
private void processTreatment(int id, Button button)
{
treatment = new Treatment(wirelessResult, id);
Alarm alarm = new Alarm(count, treatment);
wirelessResult.GenerateNumber();
alarm.setColor();
events.add(alarm);
if (getResult(treatment) == true)
{
storeSuccess(button);
}
else if (getResult(treatment) == false)
{
storeFailed(button);
}
}
// image clicked
private void treatmentStation1_Click(object sender, EventArgs e)
{
Form2 secondForm = new Form2(treatment);
secondForm.Show();
}
并在form2中:
public partial class Form2 : Form
{
private Treatment treatment;
public Form2()
{
InitializeComponent();
}
public Form2(Treatment treatment)
{
InitializeComponent();
this.treatment = treatment;
}
}
}
我得到1错误:错误1不一致的可访问性:参数类型'WasteTreatment.Treatment'的访问比方法'WasteTreatment.Form2.Form2(WasteTreatment.Treatment)'少。
有人可以帮我解决这个问题吗?
最佳答案
private Treatment treatment
只能在Form1
中使用,因为您已将其标记为private
。
我认为纠正问题的最佳方法是这样的:
Form2 secondForm = new Form2(new Treatment(wirelessResult, id));
您可以将
wirelessResult
和id
设为Form1
的私有成员。09-07 01:25