Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

QueryContinueDragEventArgs.Action Propriedade

Obtém ou define o status de uma operação arrastar-e-soltar.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (em System.Windows.Forms. dll)

public DragAction Action { get; set; }

Valor da propriedade

Tipo: System.Windows.Forms.DragAction
A DragAction value.

By default, the QueryContinueDrag event sets Action to DragAction.Cancel if the ESC key was pressed and sets Action to DragAction.Drop if the left, middle, or right mouse button is pressed.

The following code example demonstrates a drag-and-drop operation between two ListBox controls.The example calls the DoDragDrop method when the drag action starts.The drag action starts if the mouse has moved more than SystemInformation.DragSize from the mouse location during the MouseDown event.The IndexFromPoint method is used to determine the index of the item to drag during the MouseDown event.

O exemplo também demonstra o uso Cursores Personalizars para a operação arrastar-e-soltar.The example assumes that two cursor files, 3dwarro.cur and 3dwno.cur, exist in the application directory, for the custom drag and no-drop cursors, respectively.The custom cursors will be used if the UseCustomCursorsCheckCheckBox is checked.The custom cursors are set in the GiveFeedback event handler.

The keyboard state is evaluated in the DragOver event handler for the right ListBox, to determine what the drag operation will be based upon state of the SHIFT, CTRL, ALT, or CTRL+ALT keys.The location in the ListBox where the drop would occur is also determined during the DragOver event.If the data to drop is not a String, then the DragEventArgs.Effect is set to DragDropEffects.None.Finally, the status of the drop is displayed in the DropLocationLabelLabel.

The data to drop for the right ListBox is determined in the DragDrop event handler and the String value is added at the appropriate place in the ListBox.If the drag operation moves outside the bounds of the form, then the drag-and-drop operation is canceled in the QueryContinueDrag event handler.

This code excerpt demonstrates using the QueryContinueDragEventArgs class with the QueryContinueDrag event.See the DoDragDrop method for the complete code example.

private void ListDragSource_QueryContinueDrag(object sender, System.Windows.Forms.QueryContinueDragEventArgs e) {
    // Cancel the drag if the mouse moves off the form.
    ListBox lb = sender as ListBox;

    if (lb != null) {

        Form f = lb.FindForm();

        // Cancel the drag if the mouse moves off the form. The screenOffset
        // takes into account any desktop bands that may be at the top or left
        // side of the screen.
        if (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) ||
            ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) ||
            ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) ||
            ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom)) {

            e.Action = DragAction.Cancel;
        }
    }
}


private void listDragSource_QueryContinueDrag(Object sender, 
    System.Windows.Forms.QueryContinueDragEventArgs e)
{
    // Cancel the drag if the mouse moves off the form.
    ListBox lb = (ListBox)sender;

    if (lb != null) {
        Form f = lb.FindForm();
        // Cancel the drag if the mouse moves off the form. The 
        // screenOffset takes into account any desktop bands 
        // that may be at the top or left side of the screen.
        if (Control.get_MousePosition().get_X() - screenOffset.get_X() 
            < f.get_DesktopBounds().get_Left() 
            || Control.get_MousePosition().get_X() 
            - screenOffset.get_X() > f.get_DesktopBounds().get_Right() 
            || Control.get_MousePosition().get_Y() - screenOffset.get_Y() 
            < f.get_DesktopBounds().get_Top() 
            || Control.get_MousePosition().get_Y() - screenOffset.get_Y() 
            > f.get_DesktopBounds().get_Bottom()) {
            e.set_Action(DragAction.Cancel);
        }
    }
} //listDragSource_QueryContinueDrag


Contribuições da comunidade

ADICIONAR
Mostrar: