Difference between revisions of "Inserting Events Stubs in CS"

From Ribbon Commander Documentation
Jump to: navigation, search
Line 1: Line 1:
 
{{DISPLAYTITLE:Inserting Events Stubs in C#}}
 
{{DISPLAYTITLE:Inserting Events Stubs in C#}}
* The .NET framework makes it easy to [[Inserting Events Stubs in CS|insert event stubs]]:
+
The .NET framework makes it easy to event stubs by using ''operator +=''.
 +
 
 +
Consider the simple example below:
 +
<syntaxhighlight lang="csharp" line>
 +
class SubscribeToEvents
 +
{
 +
    public SubscribeToEvents()
 +
    {
 +
        // Create a new button
 +
        rxButton myButton = new rxButton();
 +
        // Subscribe to its 'onAction' event
 +
        myButton.OnActionEvent += myButton_OnActionEvent;
 +
    }
 +
 
 +
    // The event stub
 +
    void myButton_OnActionEvent(IRibbonControl control)
 +
    {
 +
        throw new NotImplementedException();
 +
    }
 +
}
 +
</syntaxhighlight>
 +
 
 
*# type <code>_myButton.OnActionEvent +=</code>
 
*# type <code>_myButton.OnActionEvent +=</code>
 
*# intellisense picks up and prompts you to press tab to insert the stub:
 
*# intellisense picks up and prompts you to press tab to insert the stub:
 
*#: [[image:InsertingEventStubCS.png|border|link=]]
 
*#: [[image:InsertingEventStubCS.png|border|link=]]
 
*# Press tab twice to insert the delegate stub and change it to display the message box as above
 
*# Press tab twice to insert the delegate stub and change it to display the message box as above
* If everything went according to plan the button will now display the following message when clicked:
 
*: [[image: FristButtonCSMsgBox.png|link=]]
 

Revision as of 15:54, 15 March 2013

The .NET framework makes it easy to event stubs by using operator +=.

Consider the simple example below:

  1. class SubscribeToEvents
  2. {
  3.     public SubscribeToEvents()
  4.     {
  5.         // Create a new button
  6.         rxButton myButton = new rxButton();
  7.         // Subscribe to its 'onAction' event
  8.         myButton.OnActionEvent += myButton_OnActionEvent;
  9.     }
  10.  
  11.     // The event stub
  12.     void myButton_OnActionEvent(IRibbonControl control)
  13.     {
  14.         throw new NotImplementedException();
  15.     }
  16. }
    1. type _myButton.OnActionEvent +=
    2. intellisense picks up and prompts you to press tab to insert the stub:
      InsertingEventStubCS.png
    3. Press tab twice to insert the delegate stub and change it to display the message box as above