2

我正在开发一个有两个窗口的表单应用程序。在主窗口中,我在 Form1 中创建了 Treatment 类的实例。我想传递那个实例,一旦图像被点击到另一个窗口 form2。到目前为止,我有: Form1:

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)”更难访问

有人可以帮我解决这个问题吗?

4

2 回答 2

1

private Treatment treatment只能在内部使用Form1,因为你已经标记了它private

我认为纠正问题的最佳方法是这样的:

Form2 secondForm = new Form2(new Treatment(wirelessResult, id));

并且您可以创建wirelessResultid私有成员Form1.

于 2012-11-07T04:26:13.770 回答
0

不一致的可访问性意味着您的WasteTreatment.Treatment类对Form2.

例如,如果Form2是 inAssemblyAWasteTreatment.TreatmentinAssemblyB并被WasteTreatment.Treatment标记为internal,则默认情况下,类 w/oa 修饰符将是。 Form2将无法使用WasteTreatment.Treatment

没有看到那门课,我只能说试着做这门课public,看看它是否有效。解决此问题的另一种方法是,如果WasteTreatment.Treatment实现接口Form2接受接口而不是具体对象,并确保接口也被标记public

于 2012-11-07T04:27:29.743 回答