我想在form1中调用form2的load,但是又不想显示form2,我现在的实现是在form1中调用form2的公用方法,公共方法中用了this.OnLoad(null);这样虽然调用了form2的load,但是抱错说:在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke。
不知道如何能实现不展示form2,却能直接调用form2的load!求高手指教!!

解决方案 »

  1.   

    那你是要调用form2的load中的方法吗?
      

  2.   

    调用form2的公共方法,不需要调用Onload啊
    form2 frm=new form2();
    frm.公共方法();
    frm.Dispose();
    frm=null;
    如果你非要调用Form2的load,又不想用户看到form2,你可以将form2的窗体设置成透明的
      

  3.   

    你为什么要调用load方法,就是想要方法里面的内容吗?
    如果是这样,那你把load里面的方法提取出来,放入一个方法中,然后通过委托事件在Form2中调用Form1中的那个方法
      

  4.   

    把Load中的代码再封装成一个方法出来
      

  5.   


    form1中
    form2 frm=new form2(this);form2中
    form1 frm1;
    public form2(form1 ff)
    {
      this.frm1=(form1)ff;
    }调用方法 frm1.公有的方法名
      

  6.   

    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 MYQQ
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        private void Form2_Load(object sender, EventArgs e)
            {
                this.Hide();
                this.ShowInTaskbar = false;
                MessageBox.Show("aa");
            }
        }
    }[code=C#]using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;namespace MYQQ
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            } 
            private void button5_Click_1(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.Show();
            }
        }
    }[/code]
      

  7.   

    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Linq; 
    using System.Text; 
    using System.Windows.Forms; 
    using System.IO; namespace MYQQ 

        public partial class Form1 : Form 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
            } 
            private void button5_Click_1(object sender, EventArgs e) 
            { 
                Form2 f2 = new Form2(); 
                f2.Show(); 
            } 
        } 
    }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 MYQQ
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        private void Form2_Load(object sender, EventArgs e)
            {
                this.Hide();
                this.ShowInTaskbar = false;
                MessageBox.Show("aa");
            }
        }
    }
      

  8.   

    对阿,我是想调用load中的方法,我把那个方法放到了form2的公共方法中了,但是却没有调用,不知道为什么,因为是调用架构中的方法,所以我怀疑他设置了什么,可能是因为必须在load中调用?所以我想先调用load。
      

  9.   

    问题没有描述清楚啊,难道你是调用的form2的静态方法,那个错误很明显是你还没有实例化form2产生的,如果实例化form2后再调用它的OnLoad方法,是不会产生错误的。