반응형
#region 프로젝트 폼 목록 읽어 오기
public static Form GetAssemblyForm(string strFormName)
{
Form f = null;
foreach (Type t in System.Reflection.Assembly.GetExecutingAssembly().GetTypes())
{
if (t.Name == strFormName) //프로젝트 내 폼 중에서 찾을 이름과 같으면...
{
object o = Activator.CreateInstance(t); //인스턴스 개체 생성
f = o as Form; //인스턴스 개체 폼 형식으로 캐스팅
}
}
return f;
}
public static List
소스 예제...
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region 프로젝트 폼 목록 읽어 오기
private Form GetAssemblyForm(string strFormName)
{
Form f = null;
foreach (Type t in System.Reflection.Assembly.GetExecutingAssembly().GetTypes())
{
if (t.Name == strFormName)
{
object o = Activator.CreateInstance(t);
f = o as Form;
}
}
return f;
}
private List<Form> GetAssemblyFormList()
{
List<Form> ltForm = new List<Form>();
listBox1.Items.Clear();
foreach (Type t in System.Reflection.Assembly.GetExecutingAssembly().GetTypes())
{
if (t.BaseType.FullName.ToString() == "System.Windows.Forms.Form")
{
object o = Activator.CreateInstance(t);
Form f = o as Form;
ltForm.Add(f);
}
}
return ltForm;
}
#endregion
private void button1_Click(object sender, EventArgs e)
{
List<Form> ltList = GetAssemblyFormList();
for (int iCount = 0; iCount < ltList.Count; iCount++)
{
Form f = ltList[iCount] as Form;
listBox1.Items.Add(f.Text);
}
}
private void button2_Click(object sender, EventArgs e)
{
Form f = GetAssemblyForm("frmSearch");
MessageBox.Show(f.Text + " 를 찾았습니다.");
}
}
}
반응형
'C# Programming' 카테고리의 다른 글
[C#] 델리 게이트 (Delegate) - 2 델리게이트 콜백과 사용 그리고 체인 (0) | 2019.09.12 |
---|---|
[C#] 델리 게이트 (Delegate) - 1 델리게이트란? , 선언 방법과 간단한 예제 (0) | 2019.09.11 |
[C#] Task Class 비동기 스레드 및 병렬 (MSDN) (0) | 2019.09.08 |
[C#] 백그라운드 스레드(BackGround Worker Class) (0) | 2019.09.07 |
[C#] Thread 사용 및 종료(MSDN) (0) | 2019.09.06 |