Difference between revisions of "Inserting Events Stubs in CS"

From Ribbon Commander Documentation
Jump to: navigation, search
 
(7 intermediate revisions by the same user not shown)
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]]:
+
== Introduction ==
*# type <code>_myButton.OnActionEvent +=</code>
+
The .NET framework makes it easy to event stubs by using ''operator +=''.
*# intellisense picks up and prompts you to press tab to insert the stub:
+
 
*#: [[image:InsertingEventStubCS.png|border|link=]]
+
== Example ==
*# Press tab twice to insert the delegate stub and change it to display the message box as above
+
Consider the simple example below:
* If everything went according to plan the button will now display the following message when clicked:
+
<syntaxhighlight lang="csharp" line highlight="10">
*: [[image: FristButtonCSMsgBox.png|link=]]
+
class SubscribeToEvents
 +
{
 +
    private rxButton _myButton;
 +
 
 +
    public SubscribeToEvents()
 +
    {
 +
        // Create a new button
 +
        _myButton = new rxButton();
 +
        // Subscribe to its 'onAction' event
 +
        _myButton.OnActionEvent += _myButton_OnActionEvent;
 +
    }
 +
 
 +
    // The event stub
 +
    void _myButton_OnActionEvent(IRibbonControl control)
 +
    {
 +
        throw new NotImplementedException();
 +
    }
 +
}
 +
</syntaxhighlight>
 +
 
 +
To insert the delegate stub (on line X) automatically you can do the following on line 8:
 +
# type <code>_myButton.OnActionEvent +=</code>
 +
# intellisense picks up and prompts you to press tab to insert the stub:
 +
#: [[image:InsertingEventStubCS.png|border|link=]]
 +
# Press tab twice. The delegate stub on line 14 will get inserted by visual studio.

Latest revision as of 17:46, 15 March 2013

Introduction

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

Example

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:
    InsertingEventStubCS.png
  3. Press tab twice. The delegate stub on line 14 will get inserted by visual studio.