Click here to Skip to main content
15,887,596 members
Articles / Desktop Programming / Windows Forms

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

Rate me:
Please Sign up or sign in to vote.
4.90/5 (3 votes)
27 Dec 2010Ms-PL2 min read 21.4K   12   3
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 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:

C#
_buttonNew.OnExecute += new OnExecuteEventHandler(_buttonNew_OnExecute);
C#
_richFont.OnPreview += new OnPreviewEventHandler(_richFont_OnPreview);
C#
_richFont.OnCancelPreview += new OnCancelPreviewEventHandler(_richFont_OnCancelPreview);

into code like this:

C#
_buttonNew.ExecuteEvent += new EventHandler<ExecuteEventArgs>(_buttonNew_OnExecute);
C#
_richFont.PreviewEvent += new EventHandler<ExecuteEventArgs>(_richFont_OnPreview);
C#
_richFont.CancelPreviewEvent += new EventHandler<ExecuteEventArgs>
				(_richFont_OnCancelPreview);

And change the method signatures from this:

C#
void _buttonNew_OnExecute(PropertyKeyRef key, PropVariantRef 
		currentValue, IUISimplePropertySet commandExecutionProperties)

to this:

C#
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:

VB.NET
AddHandler _buttonNew.OnExecute, AddressOf _buttonNew_OnExecute
VB.NET
AddHandler _richFont.OnPreview, AddressOf _richFont_OnPreview
VB.NET
AddHandler _richFont.OnCancelPreview, AddressOf _richFont_OnCancelPreview

into code like this:

VB.NET
AddHandler _buttonNew.ExecuteEvent, AddressOf _buttonNew_ExecuteEvent
VB.NET
AddHandler _richFont.PreviewEvent, AddressOf _richFont_PreviewEvent
VB.NET
AddHandler _richFont.CancelPreviewEvent, AddressOf _richFont_CancelPreviewEvent

And change the method signatures from this:

VB.NET
Private Sub _buttonNew_OnExecute(ByVal key As PropertyKeyRef, _
	ByVal currentValue As PropVariantRef, _
	ByVal commandExecutionProperties As IUISimplePropertySet)

to this:

VB.NET
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.

This article was originally posted at http://feeds.feedburner.com/ArikPoznanskisBlog

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).

Comments and Discussions

 
General... Pin
Siddharth Trehan15-Dec-10 19:06
Siddharth Trehan15-Dec-10 19:06 
GeneralMy vote of 1 Pin
JalalAldeen28-Oct-10 15:41
JalalAldeen28-Oct-10 15:41 
GeneralRe: My vote of 1 Pin
LloydA1113-Dec-10 10:10
LloydA1113-Dec-10 10:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.