using System.Collections;
Hashtable ht = new Hashtable();
private void Form1_Load(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
Form3 frm3 = new Form3();
HashTableAddForm("Form2", frm2);
HashTableAddForm("Form3", frm3);
}
private void button1_Click(object sender, EventArgs e)
{
HashTableShowForm("Form2");
}
private void HashTableAddForm(string sKey, Form form)
{
if (!ht.Contains(sKey)) //키 값 비교
{
ht.Add(sKey, form); //키 값, 폼 객체 추가
}
}
private void HashTableShowForm(string sKey)
{
if (ht.Contains(sKey)) //키 값 비교
{
Form frm = (Form)ht[sKey]; //Form 객체 변환
frm.ShowDialog(); //화면 출력
}
}
//하나의 프로젝트에 많은 Form을 사용할 경우 참고 할 만한 코드가 될 듯 합니다.
'C#' 카테고리의 다른 글
[C#]클래스 내 멤버 이름 가져오기 예제 (0) | 2018.06.11 |
---|---|
[C#]interface 예제 (0) | 2018.05.24 |
[C#]마우스 이벤트(mouse_event) 예제 (0) | 2018.05.21 |
[C#]PrintWindow를 이용한 화면캡쳐 예제 (0) | 2018.05.18 |
[C#]win api를 이용한 키보드 이벤트(keybd_event) 예제 (0) | 2018.05.18 |