What does the "On" prefix implement in case of cases in C # coding?

I think there is quite a bit of confusion about using "On" as the prefix of the C # method.

The MSDN article Handling and Enhancing Events https://msdn.microsoft.com/en-us/library/edzehd2t(v=vs.110).aspx says:

Typically, to create an event , you add a method that is marked as protected and virtual (in C #) or protected and overridden (in Visual Basic). Name this method OnEventName ; e.g. OnDataReceived. the method should take one parameter that indicates the event data object. You provide this method to allow derived classes to redefine logic to raise an event. A derived class should always call OnEventName of the base class to ensure that registered delegates receive the event.

specifying the On ... method to raise the event. Nevertheless, in many coding examples, even some provided by Microsoft, we can see the event that is used in the On method, used as an event handler, for example, here https://msdn.microsoft.com/en-us/windows/ uwp / gaming / tutorial - adding-move-look-controls-to-your-directx-game? f = 255 & MSPPError = -2147217396

First, let me fill in the mouse pointer and mouse pointer . In the first event handler, OnPointerPressed (), we get the xy coordinate of the pointer from CoreWindow, which controls ours when the user clicks on the mouse or touches the screen to see the controller area.

void MoveLookController::OnPointerPressed(
_In_ CoreWindow^ sender,
_In_ PointerEventArgs^ args)
{
    // Get the current pointer position.
    uint32 pointerID = args->CurrentPoint->PointerId;
    DirectX::XMFLOAT2 position = DirectX::XMFLOAT2( args->CurrentPoint->Position.X, args->CurrentPoint->Position.Y );

    auto device = args->CurrentPoint->PointerDevice;
    auto deviceType = device->PointerDeviceType;
    if ( deviceType == PointerDeviceType::Mouse )
    {
        // Action, Jump, or Fire
    }

    // Check  if this pointer is in the move control.
    // Change the values  to percentages of the preferred screen resolution.
    // You can set the x value to <preferred resolution> * <percentage of width>
    // for example, ( position.x < (screenResolution.x * 0.15) ).

    if (( position.x < 300 && position.y > 380 ) && ( deviceType != PointerDeviceType::Mouse ))
    {
        if ( !m_moveInUse ) // if no pointer is in this control yet
        {
            // Process a DPad touch down event.
            m_moveFirstDown = position;                 // Save the location of the initial contact.
            m_movePointerPosition = position;
            m_movePointerID = pointerID;                // Store the id of the pointer using this control.
            m_moveInUse = TRUE;
        }
    }
    else // This pointer must be in the look control.
    {
        if ( !m_lookInUse ) // If no pointer is in this control yet...
        {
            m_lookLastPoint = position;                         // save the point for later move
            m_lookPointerID = args->CurrentPoint->PointerId;  // store the id of pointer using this control
            m_lookLastDelta.x = m_lookLastDelta.y = 0;          // these are for smoothing
            m_lookInUse = TRUE;
        }
    }
}

My questions:

  • "On" ? "On" ?
  • ? ? ?
+4
1

, : " " OnSomeCondition() . , , SomeCondition, OnSomeCondition().

, : Visual Studio , someClass_SomeCondition ( , #, ). #, ( , "" ).

, , , protected virtual, "" : SomeCondition, OnSomeCondition().

, On ", " ", OnCondition() - , OnCondition(). , :

, .

+1

Source: https://habr.com/ru/post/1661953/


All Articles