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 WindowsForms01
{
       public partial class Control01 : Form
       {
             //부모컨트롤 - 자식컨트롤
             //컨테이너 컨트롤 : 자신의 영역내에 다른
컨트롤을 추가할수 있는 컨트롤.
             //(추가된 컨트롤 == 자식 컨트롤)
             private Button btn = new Button();
             public Control01()
             {
                    InitializeComponent();
             }
             private void button1_Click(object
sender, EventArgs e)
             {
                    //폼의 자식들을 관리하고 있다(컨트롤)
                    //this.button1 : 폼에 던져진 컨트롤은 자동으로 폼클래스의 멤버변수 추가된다.
                    // - this.컨트롤Name으로 접근 가능
                    // - 컨트롤은 컬렉션 형태이다.
                    Control.ControlCollection cc = this.Controls;
                    MessageBox.Show(cc.Count.ToString());
             }
             private void button2_Click(object
sender, EventArgs e)
             {
                    //동적으로 컨트롤을 추가하기
                    //1. 컨트롤 생성하기
                    // - 컨트롤은 이미 화면 상에 보여져 있는 누군가의 자식으로 들어가야 한다.
                    
                    
                    //1.5 컨트롤 속성 지정하기
                    btn.Text = "동적 생성된 버튼";
                    btn.Size = new Size(150, 50);
                    btn.Location = new
Point(50, 150);
                    //1.6 동적으로 이벤트 추가
                    btn.Click += new EventHandler(btn_Click);
                    //2. 이미 화면에 보이는 컨테이너 컨트롤의 자식으로 추가하기
                    this.Controls.Add(btn);
             }
             void btn_Click(object sender, EventArgs
e)
             {
                    //동적으로 추가된 버튼이 클릭될떄 발생
                    MessageBox.Show("쨘~");
             }
             private void button3_Click(object
sender, EventArgs e)
             {
                    //컨트롤 삭제하기
                    // - this.Controls : 컬렉션
                    //   Add() : 자식으로추가
                    //   Remove() : 삭제
                    //this.button1.Hide();
: 값이 현재 보존되고 있는 상태 : 기존에 있는 컨트롤 아예 삭제 
                    // 
                    this.Controls.Remove(btn);
                    
             }
             private void button4_Click(object
sender, EventArgs e)
             {
                    //Panel의 자식으로 컨트롤 추가하기
                    //자식을 갖는 요소들은 거의 끝에 s가 붙는다.
                    TextBox txt = new TextBox();
                    txt.Location = new
Point(10, 10);
                    this.panel1.Controls.Add(txt);
             }
       }
}