C\#MDI 하위 창 을 설정 하면 하나만 팝 업 할 수 있 는 방법

2309 단어 C#MDI창문
Windows 프로 그래 밍 의 MDI(Multiple Document Interface)공식 해석 은 이른바 다 중 문서 인터페이스 이다.이에 대응 하면 단일 문서 인터페이스(SDI)가 있다.이것 은 마이크로소프트 회사 가 Windows 2.0 의 Microsoft Excel 스프 레 드 시트 프로그램 에서 도입 한 것 이다.Excel 스프 레 드 시트 사용 자 는 여러 개의 표를 동시에 조작 해 야 할 때 가 있다.MDI 는 이러한 다 중 표 조작 에 큰 편 의 를 제공 하여 MDI 프로그램 이 생 겼 다.
WindowForm 프로그램 을 새로 만 듭 니 다.우리 아버지 창문 으로 창 을 가 져 옵 니 다.Parent.메뉴 스 트 립 공간 에 끌 어 다 놓 으 십시오.새 창 에 FrmChildren 을 우리 의 하위 창 으로 만 듭 니 다.화면 은 다음 그림 과 같 습 니 다.

그 코드 는 다음 과 같다.

public Form1()
{
  InitializeComponent();
  // Form1   MDI  ,   Form1 IsMdiContainer       
  this.IsMdiContainer = true;
}
menu strip 에서 하위 창 을 여 는 이벤트 코드 는 다음 과 같 습 니 다.

private void tsmiOpenWindow_Click(object sender, EventArgs e)
{  
  FrmChildren child = FrmChildren.GetWindow();//    
  child.MdiParent = this;//  child         
  child.Show();
  
}
GetWindow()이 방법 은 어디 에 있 습 니까?당연히 FrmChildren 창 에 써 있 죠.

 public partial class FrmChildren : Form
  {
    private FrmChildren() //  public FrmChildren   private FrmChildren
    {
      InitializeComponent();
    }
    static FrmChildren fc = null;         
    public static FrmChildren GetWindow()
    {  //              。        
      if (fc==null||fc.IsDisposed)
      {
        fc = new FrmChildren();
      }
      return fc;
    }
  }

두 번 째 방법:
이런 방법 은 개인 적 으로 매우 간단 하 다 고 생각한다.메뉴 스 트 립 에서 하위 창 을 여 는 이벤트 아래 에 바로 쓰 시 면 됩 니 다.

private void tsmiOpenWindow_Click(object sender, EventArgs e)
{ 

#region    Application       ,       ,     Name  
//   .    Name FrmChildren    ,     。              ,      。
if (Application.OpenForms["FrmChildren"] == null)
{
FrmChildren child = new FrmChildren();
child.MdiParent = this;
child.Show();
}
else// Name FrmChildren    ,   show()
{
Application.OpenForms["FrmChildren"].Show();
}
#endregion
}

관심 이 있 는 친 구 는 본문 에서 말 한 예 시 를 디 버 깅 하여 실행 할 수 있 으 며,적지 않 은 수확 이 있 을 것 이 라 고 믿는다.

좋은 웹페이지 즐겨찾기