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 ) ;

    }

  • 相关阅读:
    全国省市区县数据库脚本
    在 PHP 中养成7个面向对象的好习惯
    DIV CSS网页布局常用的方法与技巧[转]
    Div弹出提示效果(原创)
    通过数据库备份还原 TFS 到新服务器(转)
    C#多线程实现方法——Task/Task.Factary
    SEH结构异常处理使用
    Windows/Unix/Linux编译C/C++添加头文件与库的搜索路径
    windows 使用技巧
    linux重要命令
  • 原文地址:https://www.cnblogs.com/luoyaoquan/p/2110856.html
Copyright © 2011-2022 走看看