zoukankan      html  css  js  c++  java
  • dynamic menu creation

    from:
    http://community.devexpress.com/forums/t/3909.aspx

    Hi forum,

    I hardly try creating a menu during runtime.
    Via reflection I get some info out of one assembly and based on this info I
    would like to build a menu.
    In my helper class where I reflect the specific assembly I create a new
    subitem with some buttonitems, attached to a dummy barmanager.
    This subitem is delivered to my main form where the 'real' main menu is.
    I attach my submenuitem to the real barmanager and my created structure is
    available. But there are no events executed.

    My Snippets are quite big, sorry for that. It would be nice if someone could
    give a kick into the right direction.


    Best regards,

    Torben Schulz



    SNIP1:

    MainForm.cs

    DevExpress.XtraBars.BarSubItem myItem = Def.TestEnvironment.Instance.Menu;
    //getting my submenuitem

    this.barManager1.Items.Add (myItem);

    this.bar21.LinksPersistInfo.AddRange(new
    DevExpress.XtraBars.LinkPersistInfo[] {new
    DevExpress.XtraBars.LinkPersistInfo(myItem)});



    SNIP2:

    myHelpClass:

    private void LoadClassesFromAssembly()

    {

    if ( TestAssembly != null )

    {

    Type [] classesInAssembly = TestAssembly.GetTypes();

    foreach (Type type in TestAssembly.GetTypes() )

    {

    //create subItem for each type == class

    DevExpress.XtraBars.BarSubItem itemy = new DevExpress.XtraBars.BarSubItem();

    itemy.Caption = type.Name;

    itemy.Name = type.Name;

    //add subItem to barManager

    this.barManager.Items.AddRange(new DevExpress.XtraBars.BarItem[]{itemy});


    //get specific methods

    LoadTestMethodsFromAssembly( type , ref itemy );  //look a few lines below!!

    //attach subItem to mainItem

    testTopic.AddItem(itemy);

    }


    }

    }



    private void LoadTestMethodsFromAssembly( Type classType, ref
    DevExpress.XtraBars.BarSubItem subItem )

    {



    foreach ( System.Reflection.MethodInfo methodInfo in
    classType.GetMethods() )

    {

    if ( methodInfo.GetCustomAttributes( _testAttributeType, false ).Length >
    0 )

    {

    DevExpress.XtraBars.BarButtonItem bbItem = new
    DevExpress.XtraBars.BarButtonItem();


    bbItem.Tag = new TestItemInfo( methodInfo, currentX, currentY );

    bbItem.Name = methodInfo.Name;

    bbItem.Caption = methodInfo.Name;

    bbItem.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(
    this.OnTestRunClicked );



    subItem.AddItems ( new DevExpress.XtraBars.BarButtonItem[]{

    new DevExpress.XtraBars.BarButtonItem(this.barManager,bbItem.Name)});


    }

    }

    //This method is never executed!!!

    private void OnTestRunClicked( object sender,
    DevExpress.XtraBars.ItemClickEventArgs args )

    {

    DevExpress.XtraBars.BarButtonItem clickedItem = args.Item as
    DevExpress.XtraBars.BarButtonItem;

    TestItemInfo testMethod = clickedItem.Tag as TestItemInfo;

    object[] coor = { testMethod.XCoordinate, testMethod.YCoordinate };

    RunTest( testMethod.TestMethod.DeclaringType.ToString(),
    testMethod.TestMethod.Name, coor ) ;

    }

  • 相关阅读:
    分子量 (Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)
    [补档]各种奇怪的韩信问题
    [补档][HNOI 2008]GT考试
    [补档][Tyvj 1728]普通平衡树
    [补档][JLOI 2017]聪明的燕姿
    [补档][NOI 2008]假面舞会
    网络基础
    操作系统
    计算机硬件
    类和对象
  • 原文地址:https://www.cnblogs.com/luoyaoquan/p/2110856.html
Copyright © 2011-2022 走看看