C#

Hagi 2019. 1. 18. 15:17



SwitchForms.zip

Form1에 버튼이 하나있음

Form2에 버튼이 하나있음


-----------------------------------------------------------------------------

Program.cs : 우선 Form1을 구동

-----------------------------------------------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using System.Windows.Forms;


namespace SwitchForms

{

    static class Program

    {

        public static ApplicationContext ac = new ApplicationContext();


        static void Main()

        {

            Form1 startForm = new Form1();

            ac.MainForm = startForm;

            Application.Run(ac);

        }

    }

}

-----------------------------------------------------------------------------

Form1.cs

-----------------------------------------------------------------------------

namespace SwitchForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            this.Hide();
            Form2 newForm = new Form2();
            newForm.Show();
            Program.ac.MainForm = newForm;
            this.Close();
        }    
    }
}

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

Form2.cs

-----------------------------------------------------------------------------

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

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form1 newForm = new Form1();
            newForm.Show();
            Program.ac.MainForm = newForm;
            this.Close();
        }
    }
}

-----------------------------------------------------------------------------



- 첨부파일

SwitchForms.zip  
   
업무에 도움이 되었습니다. 감사합니다.