RibbonX主要控件介绍(1)

下面我们来看看使用RibbonX可以创建的不同的按钮类型。Ribbon是一个二维的UI空间,在Excel内置组中,在控件和控件排列上有相当的不同。扩展的模型暴露了一些丰富且灵活可用的不同的Ribbon控件类型,按钮也不例外。下面是一个XML代码模型,您可以将代码片断插入到下面的代码中。
<customUI xmlns=”http://schemas.microsoft.com/office/2006/01/customui“>
  <ribbon>
    <tabs>
      <tab idMso=”TabAddIns”>
        <!– insert snippet here –>
      </tab>
    </tabs>
  </ribbon>
</customUI>
按钮(Button)
Ribbon扩展是关于开发者如何使自定义按钮显示在Ribbon中。按钮可以是大的或小的,可以显示或隐藏其标签,也可以有工具提示或超级提示。像所有在RibbonX中自定义的控件都有图像一样,可以使用imageMso属性从内置按钮中复制其图像。
CustomButton
图1:四个自定义按钮,每个按钮的图像都来自于内置控件
<group id=”myGroup” label=”My Group”>
 
  <button id=”b1″ imageMso=” HyperlinkInsert”
    size=”large” label=”Surf the Net” onAction=”surf”/>
 
  <button id=”b2″ imageMso=”HappyFace”
    label=”Smile” onAction=”smile”/>

  <button id=”b3″ imageMso=”FormatPainter” label=”Paint”
    onAction=”paint”/>

  <button id=”b4″ imageMso=”AutoFilterClassic” label=”Filter”
    onAction=”filter”/>

</group>
也可以隐藏内置按钮的标签,获取小的16×16图标显示,像非Ribbon应用程序中工具栏上的图标一样。大的按钮图像是32×32像素。
CustomButtonNoLabel
图2:使用showLabel属性隐藏标签
<group id=”myGroup” label=”My Group”>
 
    <button id=”b1″ imageMso=”HyperlinkInsert”
      size=”large” label=”Surf the Net” onAction=”surf” />
 
    <button id=”b2″ imageMso=”HappyFace”
      showLabel=”false” label=”Smile” onAction=”smile” />

    <button id=”b3″ imageMso=”FormatPainter”
            showLabel=”false” label=”Paint” onAction=”paint” />

    <button id=”b4″ imageMso=”AutoFilterClassic”
    showLabel=”false” label=”Filter” onAction=”filter” />

</group>
切换按钮(ToggleButtons)
切换按钮的一个规范示例是“加粗(Bold)”按钮。可以创建自已的切换按钮,通过回调使它们的行为就像加粗按钮一样。对第一个示例的XML进行调整,得到一对切换按钮。
CustomToggleButton 
图3:单击后的切换按钮
<group id=”myGroup” label=”My Group”>
 
    <toggleButton id=”b1″ imageMso=”HyperlinkInsert”
      size=”large” label=”Surf the Net” onAction=”surf” />
 
    <button id=”b2″ imageMso=”HappyFace”
      showLabel=”false” label=”Smile” onAction=”smile” />

    <toggleButton id=”b3″ imageMso=”FormatPainter”
            showLabel=”false” label=”Paint” onAction=”paint” />

    <button id=”b4″ imageMso=”AutoFilterClassic”
    showLabel=”false” label=”Filter” onAction=”filter” />

</group>
SplitButtons
SplitButtons联合了单击按钮和一组可供选择的菜单。下图是一个放置在Ribbon中的一个splitButton,其中使用了现存的按钮图像。
CustomSplitButton 
图4:SplitButton的下拉菜单
<group id=”myGroup” label=”My Group”>
 
    <splitButton id=”mySplit” size=”large”>

              <button id=”b1″ imageMso=”HyperlinkInsert”
        label=”Surf the Net” onAction=”surf” />
 
      <menu id=”splitMenu” itemSize=”large”>

            <button id=”b2″ imageMso=”HappyFace” label=”Smile”
                 onAction=”smile” description=”View pages about smiles.” />

          <button id=”b3″ imageMso=”FormatPainter” label=”Paint”
                 onAction=”paint” description=”Learn to paint your house.” />

         <button id=”b4″ imageMso=”AutoFilterClassic” onAction=”filter”
                 description=”Read about water purification.” />
              </menu>
            </splitButton>
</group>
按钮排列
可以有大的和小的按钮,可以设置属性如可见性、启用状态和动态标签。可能您已注意到在Ribbon应用程序中一些选项卡内的一些各式各样的按钮,也可以在RibbonX中创建自已的按钮组(buttonGroups)。下面的例子使用idMso抓取了内置的Office控件。
buttonGroups 
图5:buttonGroups
<group id=”myGroup” label=”My Group”>
 
    <button id=”r1″ label=”Vanilla Button” imageMso=”Cut” />

            <buttonGroup id=”myBGroup”>
               <button id=”b1″ imageMso=”HyperlinkInsert”
          label=”Surf the Net” onAction=”surf” />
 
       <button id=”b2″ imageMso=”HappyFace” label=”Smile”
                 onAction=”smile” />
            </buttonGroup>

  <buttonGroup id=”myBGroup2″>           
               <button id=”b3″ imageMso=”FormatPainter” label=”Paint”
                 showLabel=”false” onAction=”paint” />

     <toggleButton idMso=”Bold” />

       <button id=”b4″ imageMso=”AutoFilterClassic” label=”Filter”
                showLabel=”false” onAction=”filter” />
            </buttonGroup>
</group>
自定义按钮图像
RibbonX支持自已的图标图像。
<group id=”myGroup” label=”My Group”>
  <button id=”M” size=”large” label=”The M Button”
    getImage=”getM”/>
</group>
在上面的示例中,使用回调getM抓取PNG文件,转换该文件为一个IpictureDisp,并返回到Office。
本文整理自:http://blogs.msdn.com/jensenh/archive


提示:您可以在评论中使用HTML标签,且任何与HTML标签相同的符号都会被理解为HTML标签并以相应的格式显示.如果您的评论中有代码,可以使用相应的标签,例如,如果有VB或VBA代码,则可以使用[vb]标签,即[vb]放置的代码[/vb],这样会很清晰地显示代码.

发表评论