简体   繁体   中英

C# - How to close current window and get new window

I'm implementing a window form in C#. I want to close current window and open a new window. (Just like File->New function in applications)

This is my code

private void newToolStripMenuItem_Click(object sender, EventArgs e)
    {
        
        Image_Editor IE = new Image_Editor(); //Image_Editor is the name of window
        IE.Show();
        this.Close();
        
    }

Images of what I want to achieve:


(source: infosight.com )

I want to implement the "new" function as shown in the above link. When executing given code, new window just appeared and both windows close at the same time.

What should I do to solve this?

if you mean that you want to close this windows and open a windows like your current windows use this

Myform frm; //thats name of the class of your form like Form1
frm = new Myform();
frm.Show(); // show the secend one
this.Close(); // and close the first one 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM