当我尝试将handel事件从表单转移到另一个时出错

问题描述 投票:-1回答:2

什么是错误原因;

{
    private Form2 testc;
    public Form1()
    {
        InitializeComponent();

    }

    private void button1_Click(object sender, EventArgs e)
    {
        button1.Visible = true;
        button2.Visible = true;
        button3.Visible = false;
        button4.Visible = true;
    }

    private void button4_Click(object sender, EventArgs e)
    {
        button1.Visible = true;
        button2.Visible = true;
        button3.Visible = true;
        button4.Visible = true;
    }

    public void button2_Click(object sender, EventArgs e)
    {
        button1.PerformClick();
    }

    public void pictureBox2_Click(object sender, EventArgs e)
    {
        button1.Visible = false;
        button2.Visible = false;
        button3.Visible = false;
        button4.Visible = true;
    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        pictureBox2_Click(this, null);
        testc = new Form2() ;
        testc.Show();
    }
}

我希望按钮上的活动按钮具有使用我需要的所有表格2的表格,但我遇到了问题。

严重性代码描述项目文件行抑制状态

错误CS0120,非静态字段,方法或属性'Form1.pictureBox2_Click(object,EventArgs)'WindowsFormsApplication7需要对象引用。>

 public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }
 private Form1 test;
    private void button5_Click(object sender, EventArgs e)
    {
        Form1.pictureBox2_Click(this, null);
    }
}

如果我在主项目中更改了这样的代码(不用于测试)

 private void button1_Click(object sender, EventArgs e)  
    {
        test = new MainForm();
        test.Refill_sy_Click(this, null);
        test.Show();

给出此错误enter image description here

什么是错误原因; {私人Form2 testc;公共Form1(){InitializeComponent(); } private void button1_Click(object sender,EventArgs e){button1 ....

c#
2个回答
0
投票

Form1type


1
投票

我发现这种方式是处理信息的最佳方式;表单中的另一个按钮执行相同的功能

© www.soinside.com 2019 - 2024. All rights reserved.