[C#]HashTable을 이용한 폼 추가, ShowDialog 예제
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을 사용할 경우 참고 할 만한 코드가 될 듯 합니다.