Difference between revisions of "Inserting Events Stubs in CS"

From Ribbon Commander Documentation
Jump to: navigation, search
Line 6: Line 6:
 
class SubscribeToEvents
 
class SubscribeToEvents
 
{
 
{
 +
    private rxButton _myButton;
 +
 
     public SubscribeToEvents()
 
     public SubscribeToEvents()
 
     {
 
     {
 
         // Create a new button
 
         // Create a new button
         rxButton myButton = new rxButton();
+
         _myButton = new rxButton();
 
         // Subscribe to its 'onAction' event
 
         // Subscribe to its 'onAction' event
         myButton.OnActionEvent += myButton_OnActionEvent;
+
         _myButton.OnActionEvent += _myButton_OnActionEvent;
 
     }
 
     }
  
 
     // The event stub
 
     // The event stub
     void myButton_OnActionEvent(IRibbonControl control)
+
     void _myButton_OnActionEvent(IRibbonControl control)
 
     {
 
     {
 
         throw new NotImplementedException();
 
         throw new NotImplementedException();
Line 23: Line 25:
  
 
To insert the delegate stub (on line X) automatically you can do the following on line 8:
 
To insert the delegate stub (on line X) automatically you can do the following on line 8:
# 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

Revision as of 16:57, 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.     private rxButton _myButton;
  4.  
  5.     public SubscribeToEvents()
  6.     {
  7.         // Create a new button
  8.         _myButton = new rxButton();
  9.         // Subscribe to its 'onAction' event
  10.         _myButton.OnActionEvent += _myButton_OnActionEvent;
  11.     }
  12.  
  13.     // The event stub
  14.     void _myButton_OnActionEvent(IRibbonControl control)
  15.     {
  16.         throw new NotImplementedException();
  17.     }
  18. }

To insert the delegate stub (on line X) automatically you can do the following on line 8:

  1. type _myButton.OnActionEvent +=
  2. intellisense picks up and prompts you to press tab to insert the stub:
    1. InsertingEventStubCS.png
    2. Press tab twice to insert the delegate stub and change it to display the message box as above