Nevron .NET Vision
Diagram for .NET / User's Guide / WinForm Components / Controller

In This Topic
    Controller
    In This Topic
    The controller is an extensible processor of mouse and keyboard events. It is represented by the NController class an instance of which can be obtained from the Controller property of each NView class instance.
    C#
    Copy Code
    // obtain the controller
    NController controller = view.Controller;
    
    Visual Basic
    Copy Code
    ' obtain the controller
    Dim controller As NController = view.Controller
    
     Tools

    The controller hosts a collection of tools, which is accessible from the Tools property. Each instancable view (i.e. NDrawingView or NLibraryView) initially populates this collection with the tools applicable for it. The controller processes the user actions delegated to it by the view, with the help of the tools possessed by it.

    See Tools for more information.

     Event processing

    Event processing refers to the algorithm, which the controller uses to process events delegated to it by the view. In general the events, which the controller receives can be classified as follows:

    When an event is dispatched to the controller, it will first ask the active tool to process it. If there is no active tool, the controller will cycle through all currently enabled tools, which can process the respective action (i.e. implement the respective interface). The processing stops when a tool indicated that it did process the event.

    Since mouse button (mouse up and down) events are the most common cases for tool activation/deactivation (e.g. most of the drag tool activate to left mouse down and deactivate on left mouse up), the controller supports a second processing pass for these events (i.e. if no tool processed the event in the first processing pass the controller will cycle through all tools once again).

    This gives tools the ability to define a second level of processing priority - that is specify on which controller pass they should activate. The need for a second activation pass is indicated by the value of the NeedsSecondMouseButtonPass property of the controller. 

    A typical case when this feature comes useful are the selector and move tools. Natively, if the user clicks on a selected shape and drags the mouse this should move the shape (activate the move tool). If the user did not click on a shape this should perform rectangular selection (activate the selector tool). The problem is that a shape can be selected on mouse click.

    If there was no double pass activation, clicking on a non selected shape will select the shape and perform rectangular selection instead of directly activating the move tool. Since there is double pass activation, the selector tool can be activated on the second processing pass. In this way the click event can select the shape and the move tool can then activate before the selector.

     Related Examples
    Windows Forms: Drawing View - Controller
    Windows Forms: Drawing View - Events Processing, Delegation and Bubbling
    See Also