调用其他表单方法

时间:2014-06-10 08:43:40

标签: c# winforms

我有2个表格,表格1和2.表格1将用于初始化表格2.表格2初始化后,表格2将调用表格1方法,但它不会起作用。我一直在寻找几个小时,但仍然不知道它是如何工作的。请帮帮我。

表格1

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

    namespace parentChildTest
    {
        public partial class Form1 : Form
        {

             public Form1()
             {
                 InitializeComponent();
             }

             private void button1_Click(object sender, EventArgs e)
             {
                 Form2 x = new Form2();
                 x.Show();
             }

             public static void callMe(){
                 MessageBox.Show("HAHAHA");
             }
        }
    }

表格2

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

namespace parentChildTest
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            /*How to call callMe()?????*/
        }
    }
}

2 个答案:

答案 0 :(得分:0)

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form1.Callme();
    }
}

答案 1 :(得分:0)

private void button1_Click(object sender, EventArgs e)
{
    Form1.callMe();
}
相关问题