Ribbon第一节:控件大全

1.结构

1.1 基本结构

        以下为一个自定义UI 的基本结构,ribbon为自定义工具栏,tabs为选项卡集合,其下是一个个自定义Tab选项卡。

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon startFromScratch="true"><!--功能区仅显示自定义项为 true;否则为 false。默认值为 false-->
        <tabs>
            <tab id="rxtabCustom1" label="My TAB1" insertBeforeMso="TabHome">
                <group id="rxgrp1" label="Group1">
                    <!--此处放控件内容-->
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

1.2 Tab—选项卡

<!--idMso为office自带选项卡-->
<!--visible选项卡可见为true,不可见为false,适用于tab,group-->
<tab idMso="TabHome" visible="true"/><!--开始-->
<tab idMso="TabData" visible="false"/><!--数据-->
<!--插入TabInsert,页面布局TabPageLayoutExcel,公式TabFormulas,视图TabReview-->

<!--自定义选项卡-->
<!--insertBeforeMso自定义选项卡插在Tabhome之前;insertafterMso-->
<tab id="rxtabCustom1" label="My TAB1" insertBeforeMso="TabHome">
</tab>

1.3 Group—组别

一个Tab选项卡下依功能进行的的分组,作用是分区命名,实例:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
	<ribbon startFromScratch="true">
		<tabs>
			<tab id="rxtabCustom1" label="My TAB1" insertBeforeMso="TabHome">
				<group id="rxgrp6" label="程序列表控件">
					<menu label="程序列表选项" id="rxmenu1" imageMso="AppointmentColorDialog" supertip="http://excelbbx.net" screentip="Excelbbx" size="large">
						<button label="试验1" id="rxmenu1btn1" imageMso="AddressBook" onAction="rxmenu1btn1_Chick" supertip="试验1" screentip="试验1123123"/>
						<menuSeparator id="分隔条001"/>
						<button label="试验2" id="rxmenu1btn2" imageMso="AutoFormatChange" onAction="rxmenu1btn2_Chick" supertip="试验2" screentip="提示"/>
						<menuSeparator id="分隔条002"/>
						<button label="试验3" id="rxmenu1btn3" imageMso="ClipArtInsert" onAction="rxmenu1btn3_Chick" supertip="试验3" screentip="提示"/>
						<menuSeparator id="分隔条003" title="分隔条加内容"/>
						<button label="试验4" id="rxmenu1btn4" imageMso="ChartTypeColumnInsertGallery" onAction="rxmenu1btn4_Chick" supertip="试验4" screentip="提示"/>
						<menuSeparator id="分隔条004"/>
						<button label="试验5" id="rxmenu1btn5" imageMso="Chart3DPieChart" onAction="rxmenu1btn5_Chick" supertip="试验5" screentip="提示"/>
						<menuSeparator id="分隔条005"/>
					</menu>
				</group>
			</tab>
		</tabs>
	</ribbon>
</customUI>

1.4 Box— 集合

将一个组别中的控件进行组合排成一行,方便控件排布美观,此结构可以不用。可选属性boxStyle设置排布方向,默认vertical。

<box id="rxSortBox1" boxStyle="vertical">
	<button id="Button4" label="生成" imageMso="PivotTableFieldSettings" onAction="getalldata"/>
	<button id="Button5" label="另存" imageMso="QuerySelectQueryType" onAction="export_excel"/>
	<button id="Button6" label="清除" imageMso="Clear" onAction="content_clear"/>
</box>

2.控件

2.1 button—按钮

<!--label标签,onAction绑定VBA中的函数名,showlabel为false表示不显示标签只有图标,默认为true-->
<!--size图标尺寸large大,默认normal-->
<button id="Button1" label="保存" imageMso="FrameSaveCurrentAs" size="large" onAction="Saveas"/>
<button id="Button2" showLabel="false" imageMso="ControlImage" onAction="picture" screentip="图览"/>

2.2 editBox—文本输入框

<editBox id="account" label="账号:" sizeString="123456789012" onChange="account_Click" showLabel="true"/>

回调函数

Sub account_Click(control As Office.IRibbonControl, text As String)
'此函数在焦点离开editbox控件后运行
debug.print text'text是在editbox中输入的文本内容
End Sub

2.3 menu—下拉按钮菜单

<!--imageMso指定图标,screentip悬停文本提示加粗,supertip提示正文-->
<menu label="程序列表选项" id="rxmenu1" imageMso="AppointmentColorDialog" supertip="xwlink1996" screentip="加微信" size="large">
	<button label="试验1" id="rxmenu1btn1" imageMso="AddressBook" onAction="rxmenu1btn1_Chick" supertip="试验1" screentip="提示"/>
	<menuSeparator id="分隔条001"/>
	<button label="试验2" id="rxmenu1btn2" imageMso="AutoFormatChange" onAction="rxmenu1btn2_Chick" supertip="试验2" screentip="提示"/>
	<menuSeparator id="分隔条002"/>
	<button label="试验3" id="rxmenu1btn3" imageMso="ClipArtInsert" onAction="rxmenu1btn3_Chick" supertip="试验3" screentip="提示"/>
	<menuSeparator id="分隔条003" title="分隔条加内容"/>
	<button label="试验4" id="rxmenu1btn4" imageMso="ChartTypeColumnInsertGallery" onAction="rxmenu1btn4_Chick" supertip="试验4" screentip="提示"/>
	<menuSeparator id="分隔条004"/>
	<button label="试验5" id="rxmenu1btn5" imageMso="Chart3DPieChart" onAction="rxmenu1btn5_Chick" supertip="试验5" screentip="提示"/>
	<menuSeparator id="分隔条005"/>
</menu>

2.4 splitButton—拆分式按钮

默认一个按钮可以点击,还有下拉按钮可供选择

<splitButton id="splitButton1" size="large" visible="true">
	<button id="button1" label="多表数据汇总" imageMso="QueryAppend" enabled="true" onAction="SheetsQather"/>
	<menu id="menu1" itemSize="large" visible="true" enabled="true" keytip="D">
		<button id="button2" label="多表数据汇总" imageMso="QueryAppend" onAction="SheetsQather"/>
		<button id="button3" label="按颜色汇总" imageMso="AppointmentColorDialog" onAction="ColorQather"/>
	</menu>
</splitButton>

 对应的回调函数

Sub SheetsQather(control As IRibbonControl)
    Dim id As String
    id = control.id
    Select Case id
        Case "button1"
            
        Case "button2"
        
    End Select
    MsgBox "多表数据汇总......请补充代码", vbOKOnly, "友情提示"
End Sub
'单击功能区中id为button3的过程所执行的过程
Sub ColorQather(control As IRibbonControl)
    MsgBox "按颜色汇总......请补充代码", vbOKOnly, "友情提示"
End Sub

2.5 dropDown—下拉选择菜单

<!--sizestring调整下拉栏宽度-->
<dropDown id="SelectFactory" label="工厂:" sizeString="123456789" onAction="factory_click">
	<item id="factory1101" label="1101"/>
	<item id="factory1102" label="1102"/>
	<item id="factory1103" label="1103"/>
	<item id="factory1104" label="1104"/>
</dropDown>

vba对应的回调函数

Public Sub factory_click(control As IRibbonControl, id As String, index As Integer)
    debug.print id
end sub

2.6 ComboBox—选择菜单可编辑

<comboBox id="SelectFactory" label="工厂:" sizeString="123456789" onChange="ComboBox1_Change">
	<item id="factory1101" label="1101"/>
	<item id="factory1102" label="1102"/>
	<item id="factory1103" label="1103"/>
	<item id="factory1104" label="1104"/>
</comboBox>

 2.7 checkBox—勾选

<!--visible为true可见,enable为true可以点击,keytip快捷键C-->
<checkBox id="rxchkR1C1" label="记住密码" visible="true" enabled="true"  getPressed="remember_getPressed" onAction="remember_click" keytip="C"/>

 回调函数

Sub remember_click(control As IRibbonControl, pressed As Boolean)
    If pressed Then   '如果参数pressed的值为true
        MsgBox "复选框:" & control.ID & "已打勾", vbOKOnly, "友情提示" 'control.ID代表当前所单击的按钮的ID号
    Else
        MsgBox "复选框:" & control.ID & "未打勾", vbOKOnly, "友情提示"
    End If
End Sub

 2.8 toggleButton—切换按钮

分为按下和弹起两个状态

<toggleButton id="toggleButton1" label="显示零值" visible="true" enabled="true" onAction="zero" imageMso="ChartTypeOtherInsertGallery" size="large" screentip="切换"  keytip="L"/>

 对应的回调函数

Sub zero(control As IRibbonControl, pressed As Boolean)
    If pressed = True Then '如果切换按钮处于按下状态
        Debug.Print True
    Else
        Debug.Print False
    End If
End Sub

2.9 separator—竖向分割条

用于组内分割,使按钮排布清晰美观

<separator id="separator1"/>

2.10 dialogBoxLauncher—对话框启动器

按钮图标位置在group右下角

<dialogBoxLauncher>
	<button id="dialogOne" screentip="工资条工具" supertip="单击可将工资明细表转换成工资条" onAction="wage" keytip="G"/>
</dialogBoxLauncher>

 2.11 labelControl—标签控件

<labelControl id="Label1" getLabel="getLabel"/>

 对应回调函数

Sub getLabel(control As IRibbonControl, ByRef returnedVal)
returnedVal = ActiveSheet.Shapes.Count  '将活动工作表中的图形对象数量赋值给参数returnedVal
End Sub

2.12 buttonGroup—按钮集合

<buttonGroup id="rxbgrpMsoControls">
	<toggleButton idMso="Bold"/>
	<toggleButton idMso="Italic"/>
	<toggleButton idMso="Underline"/>
	<toggleButton idMso="UnderlineDouble" showLabel="false"/>
</buttonGroup>

 2.13 buttonGroup—按钮集合

<gallery id="gallery1" label="图库" size="large" columns="3" rows="3" imageMso="HappyFace" onAction="galleryAction">
    <item id="item1" image="图片1" label="选项1" />
    <item id="item2" image="图片2" label="选项2" />
    <item id="item3" image="图片3" label="选项3" />
</gallery>

动态加载

<gallery id="gallery1" label="动态图库" size="large" columns="3" rows="3" getItemCount="getItemCount" getItemID="getItemID" getItemImage="getItemImage" getItemLabel="getItemLabel" onAction="galleryAction" />

回调

public int getItemCount(IRibbonControl control) {
    // 返回图库中的选项数量
    return 3;
}

public string getItemID(IRibbonControl control, int index) {
    // 返回指定索引项的 ID
    return "item" + (index + 1);
}

public IImage getItemImage(IRibbonControl control, int index) {
    // 返回指定索引项的图标
    return LoadImage("图片" + (index + 1));
}

public string getItemLabel(IRibbonControl control, int index) {
    // 返回指定索引项的标签
    return "选项" + (index + 1);
}

public void galleryAction(IRibbonControl control, string selectedID, int selectedIndex) {
    // 处理用户选择的选项
    MessageBox.Show("您选择了:" + selectedID);
}

分组显示

<gallery id="gallery1" label="分组图库" size="large" columns="3" rows="3">
    <menu id="menu1" label="分组1">
        <button id="button1" image="图片1" label="选项1" />
        <button id="button2" image="图片2" label="选项2" />
    </menu>
    <menu id="menu2" label="分组2">
        <button id="button3" image="图片3" label="选项3" />
        <button id="button4" image="图片4" label="选项4" />
    </menu>
</gallery>

技术交流:


作者其他作品:

Ribbon第二节:实战案例分享

VBA实战(Excel)(4):实用功能整理

HTML实战(3):实现按钮的功能

HTML实战(6):静态网页的“数据库”

代码转载自:https://pan.quark.cn/s/90d367acfca4 System.Windows.Forms.Ribbon是.NET Framework中一个用于在开发Windows Forms应用程序时构建功能区界面的控件集合。 功能区界面,类似于Microsoft Office的界面布局,提供了一种高效且用户友好的途径来组织和展示应用程序的功能特性。 这个控件集合是.NET WinForm的一个延伸,使得程序员能够便捷地在他们的应用程序中整合这一现代化的用户界面组件。 在C#编程环境里,程序员可以利用System.Windows.Forms.Ribbon库来设计个性化的功能区,包括各种按钮、下拉菜单、选项卡和工具栏等组件。 这个库提供了丰富的应用程序接口,允许开发者通过编程方式控制功能区的视觉表现和操作行为,比如增加、移除或调整选项卡,设定按钮的图标和文本内容,以及定义按钮被点击时触发的动作等。 以下是运用System.Windows.Forms.Ribbon控件时的一些核心要点:1. **RibbonForm**: 这是一种包含Ribbon控件的特定窗体类型,它替换了常规的Form类别。 在C#中,需要构建一个RibbonForm实例作为应用程序的主窗口。 2. **RibbonTab**: 功能区由多个选项卡构成,每个选项卡代表一组相关的功能单元。 可以建立RibbonTab对象并将其添加至Ribbon控件中。 3. **RibbonButton, RibbonDropDownButton, RibbonSplitButton**: 这些是功能区上的基本交互组件,分别对应于单击式按钮、下拉式按钮和分隔式按钮。 可以设定它们的Text、Image属性,并关联...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xwLink1996

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值