惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - rudyshen

我的自信到哪里去啦 了解一下自己 最近失业啦 XtraGrid控件3——3种GridView的属性 C#命名规范,控件、数据类型、ADO.NET等 C# 跳转语句(break,continue,goto,return,throw) Winform中通过一个字符串定位到和字符串相等ID的控件(将字符串转换成相应的控件名称) - rudyshen - 博客园 用户控件笔记<原创> XML笔记<原创> 什么时候应当使用interface?什么时候应当使用abstract class? XML操作<转> 怎样从DevExpress 7.1.1升级到DevExpress 7.3.5<原创> 怎样从DevExpress 7.1.1升级到DevExpress 7.3.5<原创> (C#)利用反射动态调用类成员[转载] Net中的反射使用入门 程序集的完全限定名与动态加载程序 DevExpress 7.3.5 笔记 C#控件属性 实现QQ中消息窗体闪烁功能 转
DevExpress 组件ToolBar、PopupMenu 使用有感 转
rudyshen · 2008-03-27 · via 博客园 - rudyshen

DevExpress 的帮助文档是在太缺乏了,他自己的帮助只有简单描述,没有样例,而它的网站上的在线帮助只有利用它的设计器设计的ToolBar、PopupMenu ,没有利用代码开发的。
虽然要利用代码开发,可以参照它设计器背后的代码,但还是有些区别的。我最近就碰见了问题:
我通过反射初始化BarButtonItem,BarSubItem按钮实例,最后在主程序把这些按钮加到ToolBar上:
在用反射实例化BarSubItem时,要用该方法:
                        BarSubItem newItem = new BarSubItem();
                        newItem.Name = intMenuItemCount.ToString();
                        newItem.Id = intMenuItemCount++;
 newMenu.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo((BarItem)item, beginGroup));
这里要注意:
1、Id必须唯一。
2、不要使用newMenu.AddItem((BarItem)item),这个方法会引起很多问题,如:beginGroup菜单分组无法实现, 我试图通过以下方法实现,但还是徒劳,而且有些编辑菜单不能使用该方法,如:BarToolbarsListItem工具栏列表菜单                   
                         BarItemLink itemLink = newMenu.AddItem((BarItem)item);
                          itemLink.BeginGroup = beginGroup;
3、在将实例化的BarSubItem加到ToolBar以后,还要递归把BarSubItem以及它的子菜单加入BarManager。
 private void AddMenuItem(DevExpress.XtraBars.BarItem menuItem)
        {
            if (menuItem != null)
            {
                //如果是编辑框工具条时使用
                if (menuItem is BarEditItem)
                {
                    this.BarMenuManager.RepositoryItems.Add((menuItem as BarEditItem).Edit);
                }
                this.BarMenuManager.Items.Add(menuItem);
                if (menuItem is DevExpress.XtraBars.BarSubItem)
                {
                    DevExpress.XtraBars.LinksInfo linksInfo = (menuItem as DevExpress.XtraBars.BarSubItem).LinksPersistInfo;
                    for (int i = 0; i < linksInfo.Count; i++)
                    {
                        AddMenuItem((BarItem)linksInfo[i].Item);
                    }
                }
            }
4、如果右键菜单也是通过反射实现的,那么在加载右键菜单时需要注意:
 public PopupMenu CreateContextMenu
{
             PopupMenu contextMenu = new PopupMenu();
                contextMenu.Popup += new EventHandler(ContextMenuPopupHandler);
            foreach (object item in buildItems)
                {
                    if (item is BarItem)
                    {
                        bool beginGroup = false;
                        beginGroup = (bool)(item as BarItem).Tag;

                        //contextMenu.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo((item as             BarItem),         beginGroup) });
                        BarItem barItem = item as BarItem;
                      
                       
                        AddMenuItem(barManager, barItem);
                        //用LinksPersistInfo右键菜单不出来
                        //contextMenu.LinksPersistInfo.Add(new LinkPersistInfo(barItem, beginGroup));
                        BarItemLink itemLink = contextMenu.AddItem(barItem);
                        itemLink.BeginGroup = beginGroup;
                    }
                }
                contextMenu.Manager = barManager; 
            return contextMenu;
}
//在此方法中注意 BarItemLink itemLink = (menuItem as BarSubItem).AddItem(item);此方法看似又多加了菜单,但实际不然,如果不用该方法,右键菜单中的菜单有子菜单时会无法显示。我就是让这个问题耗了我很多事间

 private void AddMenuItem(DevExpress.XtraBars.BarManager barManager,DevExpress.XtraBars.BarItem menuItem)
        {
            if (menuItem != null)
            {             
                barManager.Items.Add(menuItem);
                if (menuItem is DevExpress.XtraBars.BarSubItem)
                {
                    DevExpress.XtraBars.LinksInfo linksInfo = (menuItem as DevExpress.XtraBars.BarSubItem).LinksPersistInfo;
                    int count = linksInfo.Count;
                    for (int i = 0; i < count; i++)
                    {
                        BarItem item = (BarItem)linksInfo[i].Item;
                        item.Manager = barManager;

                        BarItemLink itemLink = (menuItem as BarSubItem).AddItem(item);
                        itemLink.BeginGroup = linksInfo[i].BeginGroup;
                        AddMenuItem(barManager, item);
                    }
                }
            }
        }