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

推荐订阅源

N
News and Events Feed by Topic
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Jina AI
Jina AI
H
Help Net Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
L
LangChain Blog
Recorded Future
Recorded Future
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
GbyAI
GbyAI
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
M
MIT News - Artificial intelligence
爱范儿
爱范儿
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
B
Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
The Cloudflare Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园 - 【当耐特】
T
Troy Hunt's Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog

博客园 - 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);
                    }
                }
            }
        }