如何从目录结构填充工具条页面? [英] How do I populate a toolstripmenu from directory structure?

查看:66
本文介绍了如何从目录结构填充工具条页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的; Per Say我已经分配了一个目录结构,负责管理每个菜单项的功能和内容。它看起来像这样:



> AppData

---> MenuStrip

---- - > __资源(离开人口,这是功能数据)

------>孩子(L1)

------ ---> __资源

--------->儿童(L2)

------------> ; __资源

--------->儿童(L2)

------------> __资源

------>儿童(L1)

---------> __资源

---- ----->孩子(L2)

------------> __资源

-------- ----> __儿童(L3)

---------------> __资源

------ >儿童(L1)

---------> __资源



其中__Resources将拥有数据每个在__Resources\properties.ini文件中的菜单项性质,__Resources\handlers.ini会对所有与动作相关的处理程序名称和__Resources\exec\(handlername)的.cs将执行h的脚本andler。目录名称本身应该是它们在菜单中出现的顺序。



所以,第1部分。如何从这样的目录结构中填充toolstripmenu和toolstripmenuitem?



更新:应用第一个解决方案之后,我得到了所需的响应。 menustrip加载了所有根条目但是条目没有加载它们的菜单项,我需要那些菜单项来加载菜单项(一直到无穷大)



最终结果将是基于源自网站导航栏的目录结构的menustrip。目录结构可以改变,以允许编程扩展网站的本地功能,如爬虫和表格海报。



FE:网站有





      
  • 我的账户

        


            
    • 配置
    •       
    • 头版
    •  &NBSP ;    
    • ect
    •     

      Alright; Per Say I have assigned a directory structure responsible for managing the functions and contents of each menu item. It looks like this:

      >AppData
      --->MenuStrip
      ------>__Resources (Leave Out Of Population, It's The Functions Data)
      ------>Child(L1)
      --------->__Resources
      --------->Child(L2)
      ------------>__Resources
      --------->Child(L2)
      ------------>__Resources
      ------>Child(L1)
      --------->__Resources
      --------->Child(L2)
      ------------>__Resources
      ------------>__Child(L3)
      --------------->__Resources
      ------>Child(L1)
      --------->__Resources

      Where the __Resources would have the data for each of the menu items properties in an __Resources\properties.ini file, the __Resources\handlers.ini would have all the handler names associated with action, and the __Resources\exec\(handlername).cs would be the execution script for that handler. The directory name itself should be the order that they appear in the menu.

      So, part1. How do I populate a toolstripmenu and toolstripmenuitem from a directory structure like this?

      UPDATE: After applying the first solution, I kind of got the desired response. The menustrip loaded all of the root entries however the entries did not load their menu items, and I need those menu items to load there menu items as well (All the way to infinity)

      The end result would be a menustrip based on a directory structure that originated from a websites navbar. The directory structure can be altered to allow programming to expand local features for the site such as crawlers and form posters.

      FE: Site Has


          
      • My Account
            

                
        • Config
        •       
        • Front Page
        •       
        • ect
        •     



                  
          • Child1
          •       
          • CHILD2
          •       
          • Child3
          •    &NBSP ;

                  
          • Child1
          •       
          • Child2
          •       
          • Child3
          •     


              
          • 我的帐户

                


                    
            • Config

                ;       


                          
              • 更改通(扩展功能从插件)
              •         

                  
              • My Account
                    

                        
                • Config
                          

                              
                  • Change Pass (Extended Feature From Plugin)
                  •         


                          
                  • Child1
                  •       
                  • CHILD2
                  •        
                  • Child3
                  •     

                          
                  • Child1
                  •       
                  • Child2
                  •       
                  • Child3
                  •     

                  推荐答案

                  如果我理解你的问题,你可以尝试这样的事情。



                  创建一个递归函数,为每个目录创建一个下拉菜单。

                  如果目录名等于__Resources,你可以读取你的ini文件并采取适当的行动。

                  You could try something like this, if I have understood your question correctly.

                  Create a recursive function that will create a drop down menu for each directory.
                  If the directory name equals __Resources, you can read your ini-file and take the proper action.
                  private void CreateMenuItem(string path, ToolStripItemCollection items)
                  {
                      foreach (string dir in Directory.GetDirectories(path))
                      {
                          if (dir.StartsWith("__"))  // instead of if (dir == "__Resources")
                          {
                              if (dir == "__Resources")
                              {
                                  // Add menu logic
                                  // The action name should come from handlers.ini, I suppose.
                                  ToolStripItem item = items.Add("Action");
                                  // Replace Item_Click with the proper handler code
                                  item.Click += Item_Click;
                              }
                              else
                              {
                                  // No idea what you should do here
                              }
                          }
                          else
                          {
                              ToolStripDropDownItem item = (ToolStripDropDownItem)items.Add(Path.GetFileName(dir));
                              CreateMenuItem(dir, item.DropDownItems);
                          }
                      }
                  }





                  首先使用start目录调用方法并初始化例如:



                  Start with calling the method with the start directory and an initialized menu strip.
                  For example:

                  CreateMenuItem(@"C:\AppData\MenuStrip", menuStrip1.Items);


                  这篇关于如何从目录结构填充工具条页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆