Pregunta

I'm trying make a MaskedTextBox, for avoid user paste value, I'm using DataObjectPastingEventHandler for process, but why that is not working?

    private void MaskPasteEvent(object sender, DataObjectPastingEventArgs e)
    {
        e.Handled = true;
    }
¿Fue útil?

Solución

What if you try this?

private void MaskPasteEvent(object sender, DataObjectPastingEventArgs e)
{
    e.CancelCommand();
}

I'm basing this off of the MSDN remark found here (4th bullet point in the remarks section):

Cancel the paste operation by calling CancelCommand.

Calling CancelCommand on the base class (DataObjectEventArgs) should set the CommandCancelled property to false on the derived DataObjectPastingEventsArgs.

Further links that may help:

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top