2013-04-13 5 views
0

방법을 통해 모든 자식 폼을 보여, 나는 아이 열 같은 코드를 사용내가 MDI 폼이 주 메뉴에 이렇게 많은 자식 폼가

 frmCustomers yeni = new frmCustomers(); 
     if (GenelIslemler.formAuthCheck(yeni.Name.ToString())) 
     { 
      if (!IsOpen(yeni.Name.ToString())) 
      { 
       yeni.MdiParent = this; 
       yeni.WindowState = FormWindowState.Maximized; 
       yeni.Show(); 

      } 
     } 
     else 
     { 
      MessageBox.Show("You dont have rights to access!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
     } 

을하지만 난 방법을 쓰고 싶어 그 메서드에 대한 양식을 호출하십시오.

openForm (frmCustomers);

와하는 OpenForm 방법은 {...}

내가 어떻게 할 수있는이

하는 OpenForm (양식 FRM)처럼해야 하는가?

답변

2

이이 질문을 해독하기위한 모든 NET 응용 프로그램

using System.Reflection; 

private void openForm(string formName) 
{ 
    // First check if this form is authorized 
    if (GenelIslemler.formAuthCheck(formName)) 
    { 
     // Then check if is already opened 
     if (!IsOpen(formName)) 
     { 
      // And now transform that string variable in the actual form to open 

      // This is the critical line. You need the fully qualified form name. 
      // namespace + classname 
      Type formType = Type.GetType ("RapunzoApps.ThisApp." + formName); 
      ConstructorInfo ctorInfo = formType.GetConstructor(Type.EmptyTypes); 
      Form theForm = (Form) ctorInfo.Invoke (null); 
      theForm.MdiParent = this; 
      theForm.WindowState = FormWindowState.Maximized; 
      theForm.Show(); 
     } 
    } 
    else 
    { 
     MessageBox.Show("You dont have rights to access!", "uyarı", MessageBoxButtons.OK, MessageBoxIcon.Error); 
    } 
} 
+0

일에 내장 된 반사 시스템을위한 작품입니다! –

+0

대단히 감사합니다. – Rapunzo