C#

017_Forms

iwannabebackendexpert 2022. 3. 30. 00:28

Form1 과 Form2를 생성해 Form1의 button text를 "form2생성"으로 변경

button를 클릭해 button1_Click 함수 생성

public Form1()
        {
            InitializeComponent();
            this.ClientSize = new System.Drawing.Size(500, 500);
            button1.Location = new System.Drawing.Point(
                500 / 2-button1.Width/2,500/2-button1.Height/2);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            this.AddOwnedForm(f2); //f2는 form1의 자식
            f2.Show();
        }

this.ClientSize : Form1의 사이즈를 500x500 픽셀의 사이즈로 만들겠다.

button1.Location : (폼의 중간 - 버튼너비의 중간), (폼의 중간 - 버튼높이의 중간) 인곳에 위치 시키겠다.

this.AddOwnedForm(f2) : f2는 form1의 자식

f2.show() : form2 화면에 띄우기 

이렇게 나타남.

또한 이전 게시물 처럼 form2에서 button을 두고 / button_Click event에 this.Close(); 로

폼을 종료하게 됨.

 

'C#' 카테고리의 다른 글

019_BasicControl  (0) 2022.03.30
018_MessageBox  (0) 2022.03.30
016_HelloWorld!(Forms)  (0) 2022.03.29
015_Hanoi_tower  (0) 2022.03.16
014_Factorial  (0) 2022.03.15