Skip to content

CheckBox and ToggleButton

harborsiem edited this page Apr 29, 2024 · 4 revisions

CheckBox and ToggleButton

In short, I’ve added support for CheckBox and ToggleButton ribbon controls. A new sample, named “10-CheckBox” has been added to the project site. The result look like this:

ToggleButton

Using CheckBox and ToggleButton – Ribbon Markup

Commands and Views sections:

<?xml version='1.0' encoding='utf-8'?>
<Application xmlns='http://schemas.microsoft.com/windows/2009/Ribbon'>
  <Application.Commands>
    <Command Name="cmdToggleButton"
             Id="1002"
             LabelTitle="Toggle Button">
      <Command.LargeImages>
        <Image>Res/Open32.bmp</Image>
      </Command.LargeImages>
      <Command.SmallImages>
        <Image>Res/Open16.bmp</Image>
      </Command.SmallImages>
    </Command>
    <Command Name="cmdCheckBox"
             Id="1003"
             LabelTitle="Check Box">
      <Command.LargeImages>
        <Image>Res/Save32.bmp</Image>
      </Command.LargeImages>
      <Command.SmallImages>
        <Image>Res/Save16.bmp</Image>
      </Command.SmallImages>
    </Command>
  </Application.Commands>
  <Application.Views>
    <Ribbon>
      <Ribbon.Tabs>
        <Tab>
          <Group>
            <ToggleButton CommandName="cmdToggleButton" />
          </Group>
          <Group CommandName="cmdGroupCheckBox">
            <CheckBox CommandName="cmdCheckBox" />
          </Group>
        </Tab>
      </Ribbon.Tabs>
    </Ribbon>
  </Application.Views>
</Application>

Using CheckBox and ToggleButton – Code Behind

Initializing:

private Ribbon _ribbon;
private RibbonToggleButton _toggleButton;
private RibbonCheckBox _checkBox;
public Form1()
{
    InitializeComponent();
    _ribbon = new Ribbon();
    _toggleButton = new RibbonToggleButton(_ribbon, (uint)RibbonMarkupCommands.cmdToggleButton);
    _checkBox = new RibbonLib.Controls.RibbonCheckBox(_ribbon, (uint)RibbonMarkupCommands.cmdCheckBox);
    _button.ExecuteEvent += new EventHandler<ExecuteEventArgs> (_button_ExecuteEvent);
}

Update (18.11.2009): The updated version of the Ribbon class provides an implementation for IUICommandHandler, so the user doesn’t need to implement Execute and UpdateProperty methods anymore.

Get / Set CheckBox status:

void _button_ExecuteEvent(object sender, ExecuteEventArgs e)
{
    MessageBox.Show("checkbox check status is: " +  _checkBox.BooleanValue.ToString());
}

Table of contents

Clone this wiki locally