如何循环得到Ribbon控件里所有的ribbon tabs,ribbon bar and button item 控件

How to loop through all ribbon tabs, ribbon bar and items on WinForms Ribbon control

If you need to loop through all ribbon tabs, ribbon bars and items on each ribbon bar here is how to do it.

C#:

foreach (BaseItem item in ribbonControl1.Items)
{
    RibbonTabItem ribbonTab = item as RibbonTabItem;
    if (ribbonTab != null)
    {
        RibbonPanel panel = ribbonTab.Panel;
        foreach (Control panelControl in panel.Controls)
        {
            RibbonBar ribbonBar = panelControl as RibbonBar;
            if (ribbonBar != null)
            {
                // At this point you can simply disable each RibbonBar and that will disable all items on it
                //ribbonBar.Enabled = false;
 
                // Here is how you loop through items on RibbonBar
                foreach (BaseItem ribbonBarItem in ribbonBar.Items)
                {
                    ribbonBarItem.Enabled = false;
                }
            }
        }
    }
}


VB:

For Each item As BaseItem In ribbonControl1.Items
Dim ribbonTab As RibbonTabItem = TryCast(item, RibbonTabItem)
If ribbonTab IsNot Nothing Then
Dim panel As RibbonPanel = ribbonTab.Panel
For Each panelControl As Control In panel.Controls
Dim ribbonBar As RibbonBar = TryCast(panelControl, RibbonBar)
If ribbonBar IsNot Nothing Then
' At this point you can simply disable each RibbonBar and that will disable all items on it
'ribbonBar.Enabled = false;

' Here is how you loop through items on RibbonBar
For Each ribbonBarItem As BaseItem In ribbonBar.Items
ribbonBarItem.Enabled = False
Next
End If
Next
End If
Next

转载于:https://www.cnblogs.com/058674/archive/2011/09/21/DotNetBar.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值