新形式不会加载C#THrowing exeption [英] New Form Wont Load C# THrowing exeption

查看:56
本文介绍了新形式不会加载C#THrowing exeption的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        private void button1_Click(object sender,EventArgs e)

        {

$
            MainTool form = new MainTool();

            this.Hide();

            form.Show();

        }

       private void button1_Click(object sender, EventArgs e)
        {

            MainTool form = new MainTool();
            this.Hide();
            form.Show();
        }

这就是我在空白表格上的按钮上...我已经这样做了因为VS不会打开我的"MainTool"....当我按下这个按钮我得到一个例外:

this is what i have on a button on a blank form....i have done this beccause VS willnot open my "MainTool".... when i press this button i get an exception:

推荐答案

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

namespace WindowsFormsApplication10
{
    public partial class Form1 : Form
    {
        public MainTool mainToolFrm;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            mainToolFrm = new MainTool(this);
            mainToolFrm.Show();
        }
    }
}

只有ar关闭事件的MainTool表单。

MainTool form with only ar closed event.

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

namespace WindowsFormsApplication10
{
    public partial class MainTool : Form
    {
        private Form1 form1;

        public MainTool(Form1 form1)
        {
            InitializeComponent();
            this.form1 = form1;
        }

        private void MainTool_FormClosed(object sender, FormClosedEventArgs e)
        {
            form1.mainToolFrm = null;
            form1.Show();
        }

    }
}

您可以根据需要来回走动。

You will be able to go back and forth as much as you want.

祝你好运





这篇关于新形式不会加载C#THrowing exeption的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆