2010-07-16 2 views
0

MdiList 속성 덕분에 모든 mdi 자식을 포함하는 'Windows'목록이있는 메뉴가 있습니다. 그러나 MDI 컨테이너 안에 메뉴에 나열하고 싶지 않은 다른 창이 있습니다. 메뉴에 쉽게 추가 할 수 있지만 MDI 하위 항목 중 하나에 메뉴가있을 때 문제가 발생합니다. 메뉴가 병합되지만 메뉴 전에 목록에 병합 된 다른 창을 추가 했으므로 올바르지 않습니다. DockPanelSuite 사용MDI 자식이 메뉴를 병합 할 때 MenuItems를 추가하는 방법

: 다음을 추가

void menuWindow_Popup(object sender, EventArgs e) 
    { 
     // Because not all windows are MDI children anymore 
     // we need to find all the other windows and add them to the menu 

     // Delete whaterver pre-existed 
     while (menuWindow.MenuItems.Count > 1) 
     { 
      menuWindow.MenuItems.RemoveAt(1); 
     } 

     if (dockPanel.FloatWindows.Count > 0) 
     { 
      menuWindow.MenuItems.Add(new MenuItem("-")); 

      // Then add all the floating/docked windows 
      // Note MDIList takes care of the windows that are in MDI mode 
      foreach (Form dockContent in dockPanel.FloatWindows) 
      { 
       // each event handler closure needs its own form reference (not a shared one) 
       Form content = dockContent; 
       var mi = new MenuItem(content.Text, 
        (EventHandler)delegate(object s, EventArgs ea) 
        { 
         if (content.WindowState == FormWindowState.Minimized) 
         { 
          content.WindowState = FormWindowState.Normal; 
         } 
         content.Show(); 
         content.Focus(); 
        }); 
       mi.Checked = (content == dockPanel.ActiveContent); 
       menuWindow.MenuItems.Add(mi); 
      } 
     } 
    } 

답변

2

음은 그것을 해결하기 위해 듯 :

 menuWindow = (MenuItem)sender; 
     if (dockPanel.ActiveDocument != null) 
     { 
      foreach (MenuItem item in ((Form)dockPanel.ActiveDocument).MergedMenu.MenuItems) 
      { 
       if (item.Text == "&Window") 
       { 
        menuWindow = item; 
       } 
      } 
     } 

을하지만 더 나은 방법

이 있는지 여전히 의문으로 떠나
관련 문제