DCSIMG
Windows Ribbon for WinForms v2.5 Released – New Events Mechanism - Arik Poznanski's Blog

Arik Poznanski's Blog

It CAN be done with .NET

News

MVP

MCC

CodeProject MVP

MCPD

MCTS

Subscribe to my blog by email

Arik Poznanski LinkedIn Profile

Email: arik.com at gmail dot com
or, use this form

Locations of visitors to this page


Sela Group

Sela Canada

DZone MVB

Links

Official Blogs

WPF / SL Blogs

Developers Blogs

Windows Ribbon for WinForms v2.5 Released – New Events Mechanism

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: 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 have 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 existing code?

If you already have code that uses 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.

Comments

No Comments