2016-06-25 5 views
1

ディレクトリにあるフォルダを表すtoolstripdropdownbuttonsを含むツールストリップがあります。私は、各toolstripdropdownボタンのドロップダウンメニューから、見つかったサブフォルダを選択したいと思います。ドロップダウンメニュー(C#Winforms)を含むツールストリップにToolstripDropDownButtonをプログラムで追加する方法

 private void populateLinks() 
    { 
     linksToolStrip.Items.Clear(); 
     DirectoryInfo linksFolder = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\\Links"); 
     foreach (DirectoryInfo linksDirectory in linksFolder.GetDirectories()) 
     { 
      Image favImage = Properties.Resources.Folder; 
      ToolStripDropDownButton button = new ToolStripDropDownButton(); 
      button.Text = Truncate(linksDirectory.Name, 22); 
      button.ToolTipText = linksDirectory.Name + "\nDate Created: " + Directory.GetCreationTime(linksDirectory.FullName); 
      button.Image = favImage; 
      button.Tag = linksDirectory.FullName; 
      linksToolStrip.Items.Add(button); 
      populateLinksFolders(linksDirectory, button.DropDown); 

     } 
:この例は Links Bar Example

(写真参照)私が試してみましたコードを、私は次のコードを試してみましたが、私はそれについて移動する方法が非常にわからないInternet Explorerのリンクバーになります

および

private void populateLinksFolders(DirectoryInfo subdirectory, ToolStripDropDown tsdd) 
    { 
     foreach (DirectoryInfo directory in subdirectory.GetDirectories()) 
     { 
      populateLinksFolders(directory, ?) //<- Everything tried here fails 
     } 
    } 

どうすればこの問題を解決できますか?

答えて

0

ToolStripDropDownButtonを渡してから、DropDownItemsプロパティを使用してサブアイテムを追加する必要があります。

populateLinksFolders(linksDirectory, button); 

その後:

private void populateLinksFolders(DirectoryInfo subdirectory, ToolStripDropDownButton tsddb) 
{ 
    foreach (DirectoryInfo directory in subdirectory.GetDirectories()) 
    { 
     ToolStripDropDownButton button = new ToolStripDropDownButton(directory.Name); 
     tsddb.DropDownItems.Add(button); 
     populateLinksFolders(directory, button); 
    } 
} 
+0

おかげで、これは私のqueston – LordPerun

+0

に答え興味深い問題は、ドロップダウンメニューが小さすぎる場所について来て、自動サイズへの道それか、この問題を修正はありますか? – LordPerun

+0

これがあなたの質問に答えるなら、答えの横にあるチェックマークを使うことを検討してください。デフォルトではボタンのサイズは自動的に変更されますが、そうでない場合は 'button.AutoSize = true;'を追加することができます。 – endofzero

関連する問題