The Windows Ribbon for WinForms is a managed wrapper around Windows Ribbon Framework, a free ribbon control that Microsoft provides in Windows 7 and Vista.
More details on this project can be found in the project site at windowsribbon.codeplex.com.
I've just released another update to the project.
Note: This release contains breaking changes, only take it if you are starting a new project, or you don't mind the needed updates to your code.
Basically, I've changed how events are exposed in the library, made it a little more .NET friendly.
The benefits of these changes are:
- You now get the control which generated the event as the sender of the event.
For example, this allows registering the same callback function to different buttons and having the ability to know which button raised the event. - You can now use the Windows Ribbon for WinForms library in languages that can work only with proper .NET event handlers. The first request for this feature was from someone who wanted to use it in Progress ABL… There is a world beyond C#, C++ and VB.NET…
How to Upgrade the Existing Code?
If you already have code that uses the previous versions of the project, follow these guidelines to do the upgrade.
Upgrading C# Code
The event names and signatures changed, thus, you need to change code like this:
_buttonNew.OnExecute += new OnExecuteEventHandler(_buttonNew_OnExecute);
_richFont.OnPreview += new OnPreviewEventHandler(_richFont_OnPreview);
_richFont.OnCancelPreview += new OnCancelPreviewEventHandler(_richFont_OnCancelPreview);
into code like this:
_buttonNew.ExecuteEvent += new EventHandler<ExecuteEventArgs>(_buttonNew_OnExecute);
_richFont.PreviewEvent += new EventHandler<ExecuteEventArgs>(_richFont_OnPreview);
_richFont.CancelPreviewEvent += new EventHandler<ExecuteEventArgs>
(_richFont_OnCancelPreview);
And change the method signatures from this:
void _buttonNew_OnExecute(PropertyKeyRef key, PropVariantRef
currentValue, IUISimplePropertySet commandExecutionProperties)
to this:
void _buttonNew_OnExecute(object sender, ExecuteEventArgs e)
Note that the ExecuteEventArgs
class holds the data that was previously passed to the execute
method directly.
Upgrading VB.NET Code
The event names and signatures changed, thus, you need to change code like this:
AddHandler _buttonNew.OnExecute, AddressOf _buttonNew_OnExecute
AddHandler _richFont.OnPreview, AddressOf _richFont_OnPreview
AddHandler _richFont.OnCancelPreview, AddressOf _richFont_OnCancelPreview
into code like this:
AddHandler _buttonNew.ExecuteEvent, AddressOf _buttonNew_ExecuteEvent
AddHandler _richFont.PreviewEvent, AddressOf _richFont_PreviewEvent
AddHandler _richFont.CancelPreviewEvent, AddressOf _richFont_CancelPreviewEvent
And change the method signatures from this:
Private Sub _buttonNew_OnExecute(ByVal key As PropertyKeyRef, _
ByVal currentValue As PropVariantRef, _
ByVal commandExecutionProperties As IUISimplePropertySet)
to this:
Private Sub _buttonNew_ExecuteEvent(ByVal sender As Object, ByVal e As ExecuteEventArgs)
Note that the ExecuteEventArgs
class holds the data that was previously passed to the execute method directly.
That’s it for now,
Arik Poznanski.