Winfrom recursive Build menu with multilevel nesting support

Source: Internet
Author: User

private void Form2_load (object sender, EventArgs e) {    createmenu ();}
private    void CreateMenu () {//define the menu strip bar bar = new Bar ("menu bar"); Bar.    MenuBar = true; Bar.    Stretch = true; Bar.    Style = edotnetbarstyle.office2003; DOTNETBARMANAGER1.BARS.ADD (bar); Add to DotNetBarManager1 object bar.    Dockside = Edockside.top;    Set Dock style System.Diagnostics.Stopwatch Stopwatch = new System.Diagnostics.Stopwatch (); Stopwatch. Start ();    Start monitoring code run time var listmenu = getbuttonitem (0); Listmenu.tolist (). ForEach (x = bar.    Items.Add (x)); Bar. RecalcLayout (); Redraw the layout stopwatch. Stop (); Stop monitoring TimeSpan timespan = stopwatch. Elapsed; Gets the total time measured by the current instance This.labelX1.Text = "Build Menu time consuming" + TimeSpan.    Totalseconds.tostring () + "MS"; Textboxx1.lostfocus + = (s, e) = = {MessageBox.Show ("lost Focus");}; 
public    Class Jsontuple<t1, t2>{public T1 Item1 {get; set;}    Public T2 Item2 {get; set;}    Public Keyvaluepair<int32, int32> kvtype {get; set;}    Public Boolean Tag {get; set;} Public Jsontuple (T1 item1, T2 item2, Keyvaluepair<int32, int32> kvtype, bool tags) {this.        Item1 = item1; This.        ITEM2 = item2; This.        Kvtype = Kvtype; This.    tag = tag; } public Jsontuple (T1 item1, T2 item2, bool tags): This (item1, item2, New Keyvaluepair<int, int> (0, 0), Ta g) {}} 
Private list<jsontuple<string, string>> Getmenusetter () {list<jsontuple<string, string>> Listmenu = new list<jsontuple<string, string>> {//& will display underline new jsontuple<string under the font, String> ("BFile", "&file", New Keyvaluepair<int, int> (1,0), false), new jsontuple<string,string> ("b Open "," open ", New Keyvaluepair<int, int> (2,1), false), new jsontuple<string,string> (" Bclose "," &close ", New Keyvaluepair<int, int> (3,1), false), new jsontuple<string,string> (" Bexit "," &exit ", New KeyValue Pair<int, Int> (4,1), true),//==================================================== new JsonTuple<str Ing,string> ("Bcut", "&cut", New Keyvaluepair<int, int> (5,0), false), new jsontuple<string,string> ( "Bcopy", "&copy", New Keyvaluepair<int, int> (6,5), false), new jsontuple<string,string> ("Bpaste", "&am P Paste ", New Keyvaluepair<int,Int> (7,5), false), new jsontuple<string,string> ("BClear", "&clear", New Keyvaluepair<int, int> (8,5    ), True),}; return listmenu;}
Private ienumerable<buttonitem> getbuttonitem (int pid) {    var listmenu = Getmenusetter ();    var query = listmenu.where (x = X.kvtype.value = = pid). Select (x =    {        var bi = new Buttonitem (x.item1, x.item2);        Bi. Tag = X.kvtype; Mark        Bi. BeginGroup = X.tag;        return bi;    });    var plist = query. ToList ();    Plist        . ForEach (            x = = x                . SubItems                . AddRange (                    Getbuttonitem (((Keyvaluepair<int, int>) x.tag). Key). ToArray ()                )        );    return plist;}
Support multilevel nesting to see the effect:





Winfrom recursive Build menu with multilevel nesting support

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.